Skip to content

Commit

Permalink
fixtures: inline fail_fixturefunc
Browse files Browse the repository at this point in the history
Doesn't add much.
  • Loading branch information
bluetech authored and nicoddemus committed Apr 27, 2024
1 parent 2e8fb9f commit 882c4da
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import _pytest
from _pytest import nodes
from _pytest._code import getfslineno
from _pytest._code import Source
from _pytest._code.code import FormattedExcinfo
from _pytest._code.code import TerminalRepr
from _pytest._io import TerminalWriter
Expand Down Expand Up @@ -864,13 +865,6 @@ def toterminal(self, tw: TerminalWriter) -> None:
tw.line("%s:%d" % (os.fspath(self.filename), self.firstlineno + 1))


def fail_fixturefunc(fixturefunc, msg: str) -> NoReturn:
fs, lineno = getfslineno(fixturefunc)
location = f"{fs}:{lineno + 1}"
source = _pytest._code.Source(fixturefunc)
fail(msg + ":\n\n" + str(source.indent()) + "\n" + location, pytrace=False)


def call_fixture_func(
fixturefunc: "_FixtureFunc[FixtureValue]", request: FixtureRequest, kwargs
) -> FixtureValue:
Expand Down Expand Up @@ -900,7 +894,13 @@ def _teardown_yield_fixture(fixturefunc, it) -> None:
except StopIteration:
pass
else:
fail_fixturefunc(fixturefunc, "fixture function has more than one 'yield'")
fs, lineno = getfslineno(fixturefunc)
fail(

Check warning on line 898 in src/_pytest/fixtures.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/fixtures.py#L897-L898

Added lines #L897 - L898 were not covered by tests
f"fixture function has more than one 'yield':\n\n"
f"{Source(fixturefunc).indent()}\n"
f"{fs}:{lineno + 1}",
pytrace=False,
)


def _eval_scope_callable(
Expand Down

0 comments on commit 882c4da

Please sign in to comment.