add test case for asserting missing fixture
This commit is contained in:
parent
bf41c9fc56
commit
ef46a374a0
|
@ -462,7 +462,7 @@ def _format_assertmsg(obj: object) -> str:
|
|||
|
||||
def _should_repr_global_name(obj: object) -> bool:
|
||||
if callable(obj):
|
||||
return hasattr(obj, "__pytest_wrapped__")
|
||||
return hasattr(obj, "_pytestfixturefunction")
|
||||
|
||||
try:
|
||||
return not hasattr(obj, "__name__")
|
||||
|
|
|
@ -1200,6 +1200,9 @@ class FixtureFunctionDefinition:
|
|||
):
|
||||
self.name = fixture_function_marker.name or function.__name__
|
||||
self.__name__ = self.name
|
||||
# This attribute is only used to check if an arbitrary python object is a fixture.
|
||||
# Using isinstance on every object in code might execute code that is not intended to be executed.
|
||||
# Like lazy loaded classes.
|
||||
self._pytestfixturefunction = fixture_function_marker
|
||||
self.__pytest_wrapped__ = _PytestWrapper(function)
|
||||
self.fixture_function_marker = fixture_function_marker
|
||||
|
|
|
@ -744,6 +744,23 @@ class TestAssertionRewrite:
|
|||
assert "UnicodeDecodeError" not in msg
|
||||
assert "UnicodeEncodeError" not in msg
|
||||
|
||||
def test_assert_fixture(self, pytester: Pytester) -> None:
|
||||
pytester.makepyfile(
|
||||
"""\
|
||||
import pytest
|
||||
@pytest.fixture
|
||||
def fixt():
|
||||
return 42
|
||||
|
||||
def test_something(): # missing "fixt" argument
|
||||
assert fixt == 42
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
["*assert pytest_fixture(<function fixt at *>) == 42*"]
|
||||
)
|
||||
|
||||
|
||||
class TestRewriteOnImport:
|
||||
def test_pycache_is_a_file(self, pytester: Pytester) -> None:
|
||||
|
|
Loading…
Reference in New Issue