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 committed Mar 17, 2024
1 parent 0bdb8e6 commit 64da72b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/_pytest/fixtures.py
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 @@ -863,13 +864,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 @@ -899,7 +893,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 897 in src/_pytest/fixtures.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/fixtures.py#L896-L897

Added lines #L896 - L897 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 64da72b

Please sign in to comment.