|
35 | 35 | import _pytest |
36 | 36 | from _pytest import nodes |
37 | 37 | from _pytest._code import getfslineno |
| 38 | +from _pytest._code import Source |
38 | 39 | from _pytest._code.code import FormattedExcinfo |
39 | 40 | from _pytest._code.code import TerminalRepr |
40 | 41 | from _pytest._io import TerminalWriter |
@@ -863,13 +864,6 @@ def toterminal(self, tw: TerminalWriter) -> None: |
863 | 864 | tw.line("%s:%d" % (os.fspath(self.filename), self.firstlineno + 1)) |
864 | 865 |
|
865 | 866 |
|
866 | | -def fail_fixturefunc(fixturefunc, msg: str) -> NoReturn: |
867 | | - fs, lineno = getfslineno(fixturefunc) |
868 | | - location = f"{fs}:{lineno + 1}" |
869 | | - source = _pytest._code.Source(fixturefunc) |
870 | | - fail(msg + ":\n\n" + str(source.indent()) + "\n" + location, pytrace=False) |
871 | | - |
872 | | - |
873 | 867 | def call_fixture_func( |
874 | 868 | fixturefunc: "_FixtureFunc[FixtureValue]", request: FixtureRequest, kwargs |
875 | 869 | ) -> FixtureValue: |
@@ -899,7 +893,13 @@ def _teardown_yield_fixture(fixturefunc, it) -> None: |
899 | 893 | except StopIteration: |
900 | 894 | pass |
901 | 895 | else: |
902 | | - fail_fixturefunc(fixturefunc, "fixture function has more than one 'yield'") |
| 896 | + fs, lineno = getfslineno(fixturefunc) |
| 897 | + fail( |
| 898 | + f"fixture function has more than one 'yield':\n\n" |
| 899 | + f"{Source(fixturefunc).indent()}\n" |
| 900 | + f"{fs}:{lineno + 1}", |
| 901 | + pytrace=False, |
| 902 | + ) |
903 | 903 |
|
904 | 904 |
|
905 | 905 | def _eval_scope_callable( |
|
0 commit comments