ENH: Improve warning stacklevel

This commit is contained in:
Eric Larson 2024-07-02 12:55:06 -04:00
parent 51ee3880c7
commit 3efcff8bd1
3 changed files with 4 additions and 1 deletions

View File

@ -0,0 +1 @@
Fix the ``stacklevel`` used when warning about marks used on fixtures.

View File

@ -1192,7 +1192,7 @@ class FixtureFunctionMarker:
)
if hasattr(function, "pytestmark"):
warnings.warn(MARKED_FIXTURE, stacklevel=2)
warnings.warn(MARKED_FIXTURE, stacklevel=4)
function = wrap_function_to_error_out_if_called_directly(function, self)

View File

@ -185,6 +185,8 @@ def test_fixture_disallow_on_marked_functions():
# from applying @fixture twice
# ValueError("fixture is being applied more than once to the same function")
assert len(record) == 1
# should point to this file
assert record[0].filename == __file__
def test_fixture_disallow_marks_on_fixtures():