fixtures: fix crash when parametrize(scope="package") is used without a Package

There as handling for `scope="class"` without a class, but not for
`scope="package"` without a package. It would fail the assert.
This commit is contained in:
Ran Benita
2023-07-28 13:54:11 +03:00
parent 448563caaa
commit 71e627aa8f
3 changed files with 31 additions and 5 deletions

View File

@@ -1486,6 +1486,23 @@ class TestMetafuncFunctional:
]
)
@pytest.mark.parametrize("scope", ["class", "package"])
def test_parametrize_missing_scope_doesnt_crash(
self, pytester: Pytester, scope: str
) -> None:
"""Doesn't crash when parametrize(scope=<scope>) is used without a
corresponding <scope> node."""
pytester.makepyfile(
f"""
import pytest
@pytest.mark.parametrize("x", [0], scope="{scope}")
def test_it(x): pass
"""
)
result = pytester.runpytest()
assert result.ret == 0
class TestMetafuncFunctionalAuto:
"""Tests related to automatically find out the correct scope for