Skip to content

Commit 882c4da

Browse files
bluetechnicoddemus
authored andcommitted
fixtures: inline fail_fixturefunc
Doesn't add much.
1 parent 2e8fb9f commit 882c4da

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/_pytest/fixtures.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import _pytest
3636
from _pytest import nodes
3737
from _pytest._code import getfslineno
38+
from _pytest._code import Source
3839
from _pytest._code.code import FormattedExcinfo
3940
from _pytest._code.code import TerminalRepr
4041
from _pytest._io import TerminalWriter
@@ -864,13 +865,6 @@ def toterminal(self, tw: TerminalWriter) -> None:
864865
tw.line("%s:%d" % (os.fspath(self.filename), self.firstlineno + 1))
865866

866867

867-
def fail_fixturefunc(fixturefunc, msg: str) -> NoReturn:
868-
fs, lineno = getfslineno(fixturefunc)
869-
location = f"{fs}:{lineno + 1}"
870-
source = _pytest._code.Source(fixturefunc)
871-
fail(msg + ":\n\n" + str(source.indent()) + "\n" + location, pytrace=False)
872-
873-
874868
def call_fixture_func(
875869
fixturefunc: "_FixtureFunc[FixtureValue]", request: FixtureRequest, kwargs
876870
) -> FixtureValue:
@@ -900,7 +894,13 @@ def _teardown_yield_fixture(fixturefunc, it) -> None:
900894
except StopIteration:
901895
pass
902896
else:
903-
fail_fixturefunc(fixturefunc, "fixture function has more than one 'yield'")
897+
fs, lineno = getfslineno(fixturefunc)
898+
fail(
899+
f"fixture function has more than one 'yield':\n\n"
900+
f"{Source(fixturefunc).indent()}\n"
901+
f"{fs}:{lineno + 1}",
902+
pytrace=False,
903+
)
904904

905905

906906
def _eval_scope_callable(

0 commit comments

Comments
 (0)