Merge master into features
Conflicts: .github/workflows/main.yml
This commit is contained in:
@@ -1716,6 +1716,138 @@ class TestAutouseDiscovery:
|
||||
reprec.assertoutcome(passed=3)
|
||||
|
||||
|
||||
class TestMultiLevelAutouseAndParameterization:
|
||||
def test_setup_and_teardown_order(self, testdir):
|
||||
"""Tests that parameterized fixtures effect subsequent fixtures. (#6436)
|
||||
|
||||
If a fixture uses a parameterized fixture, or, for any other reason, is executed
|
||||
after the parameterized fixture in the fixture stack, then it should be affected
|
||||
by the parameterization, and as a result, should be torn down before the
|
||||
parameterized fixture, every time the parameterized fixture is torn down. This
|
||||
should be the case even if autouse is involved and/or the linear order of
|
||||
fixture execution isn't deterministic. In other words, before any fixture can be
|
||||
torn down, every fixture that was executed after it must also be torn down.
|
||||
"""
|
||||
testdir.makepyfile(
|
||||
test_auto="""
|
||||
import pytest
|
||||
def f(param):
|
||||
return param
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def s_fix(request):
|
||||
yield
|
||||
@pytest.fixture(scope="package", params=["p1", "p2"], ids=f, autouse=True)
|
||||
def p_fix(request):
|
||||
yield
|
||||
@pytest.fixture(scope="module", params=["m1", "m2"], ids=f, autouse=True)
|
||||
def m_fix(request):
|
||||
yield
|
||||
@pytest.fixture(scope="class", autouse=True)
|
||||
def another_c_fix(m_fix):
|
||||
yield
|
||||
@pytest.fixture(scope="class")
|
||||
def c_fix():
|
||||
yield
|
||||
@pytest.fixture(scope="function", params=["f1", "f2"], ids=f, autouse=True)
|
||||
def f_fix(request):
|
||||
yield
|
||||
class TestFixtures:
|
||||
def test_a(self, c_fix):
|
||||
pass
|
||||
def test_b(self, c_fix):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("--setup-plan")
|
||||
test_fixtures_used = (
|
||||
"(fixtures used: another_c_fix, c_fix, f_fix, m_fix, p_fix, request, s_fix)"
|
||||
)
|
||||
result.stdout.fnmatch_lines(
|
||||
"""
|
||||
SETUP S s_fix
|
||||
SETUP P p_fix[p1]
|
||||
SETUP M m_fix[m1]
|
||||
SETUP C another_c_fix (fixtures used: m_fix)
|
||||
SETUP C c_fix
|
||||
SETUP F f_fix[f1]
|
||||
test_auto.py::TestFixtures::test_a[p1-m1-f1] {0}
|
||||
TEARDOWN F f_fix[f1]
|
||||
SETUP F f_fix[f2]
|
||||
test_auto.py::TestFixtures::test_a[p1-m1-f2] {0}
|
||||
TEARDOWN F f_fix[f2]
|
||||
SETUP F f_fix[f1]
|
||||
test_auto.py::TestFixtures::test_b[p1-m1-f1] {0}
|
||||
TEARDOWN F f_fix[f1]
|
||||
SETUP F f_fix[f2]
|
||||
test_auto.py::TestFixtures::test_b[p1-m1-f2] {0}
|
||||
TEARDOWN F f_fix[f2]
|
||||
TEARDOWN C c_fix
|
||||
TEARDOWN C another_c_fix
|
||||
TEARDOWN M m_fix[m1]
|
||||
SETUP M m_fix[m2]
|
||||
SETUP C another_c_fix (fixtures used: m_fix)
|
||||
SETUP C c_fix
|
||||
SETUP F f_fix[f1]
|
||||
test_auto.py::TestFixtures::test_a[p1-m2-f1] {0}
|
||||
TEARDOWN F f_fix[f1]
|
||||
SETUP F f_fix[f2]
|
||||
test_auto.py::TestFixtures::test_a[p1-m2-f2] {0}
|
||||
TEARDOWN F f_fix[f2]
|
||||
SETUP F f_fix[f1]
|
||||
test_auto.py::TestFixtures::test_b[p1-m2-f1] {0}
|
||||
TEARDOWN F f_fix[f1]
|
||||
SETUP F f_fix[f2]
|
||||
test_auto.py::TestFixtures::test_b[p1-m2-f2] {0}
|
||||
TEARDOWN F f_fix[f2]
|
||||
TEARDOWN C c_fix
|
||||
TEARDOWN C another_c_fix
|
||||
TEARDOWN M m_fix[m2]
|
||||
TEARDOWN P p_fix[p1]
|
||||
SETUP P p_fix[p2]
|
||||
SETUP M m_fix[m1]
|
||||
SETUP C another_c_fix (fixtures used: m_fix)
|
||||
SETUP C c_fix
|
||||
SETUP F f_fix[f1]
|
||||
test_auto.py::TestFixtures::test_a[p2-m1-f1] {0}
|
||||
TEARDOWN F f_fix[f1]
|
||||
SETUP F f_fix[f2]
|
||||
test_auto.py::TestFixtures::test_a[p2-m1-f2] {0}
|
||||
TEARDOWN F f_fix[f2]
|
||||
SETUP F f_fix[f1]
|
||||
test_auto.py::TestFixtures::test_b[p2-m1-f1] {0}
|
||||
TEARDOWN F f_fix[f1]
|
||||
SETUP F f_fix[f2]
|
||||
test_auto.py::TestFixtures::test_b[p2-m1-f2] {0}
|
||||
TEARDOWN F f_fix[f2]
|
||||
TEARDOWN C c_fix
|
||||
TEARDOWN C another_c_fix
|
||||
TEARDOWN M m_fix[m1]
|
||||
SETUP M m_fix[m2]
|
||||
SETUP C another_c_fix (fixtures used: m_fix)
|
||||
SETUP C c_fix
|
||||
SETUP F f_fix[f1]
|
||||
test_auto.py::TestFixtures::test_a[p2-m2-f1] {0}
|
||||
TEARDOWN F f_fix[f1]
|
||||
SETUP F f_fix[f2]
|
||||
test_auto.py::TestFixtures::test_a[p2-m2-f2] {0}
|
||||
TEARDOWN F f_fix[f2]
|
||||
SETUP F f_fix[f1]
|
||||
test_auto.py::TestFixtures::test_b[p2-m2-f1] {0}
|
||||
TEARDOWN F f_fix[f1]
|
||||
SETUP F f_fix[f2]
|
||||
test_auto.py::TestFixtures::test_b[p2-m2-f2] {0}
|
||||
TEARDOWN F f_fix[f2]
|
||||
TEARDOWN C c_fix
|
||||
TEARDOWN C another_c_fix
|
||||
TEARDOWN M m_fix[m2]
|
||||
TEARDOWN P p_fix[p2]
|
||||
TEARDOWN S s_fix
|
||||
""".format(
|
||||
test_fixtures_used
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class TestAutouseManagement:
|
||||
def test_autouse_conftest_mid_directory(self, testdir):
|
||||
pkgdir = testdir.mkpydir("xyz123")
|
||||
|
||||
@@ -146,12 +146,16 @@ def test_is_generator_async_gen_syntax(testdir):
|
||||
|
||||
|
||||
class ErrorsHelper:
|
||||
@property
|
||||
def raise_baseexception(self):
|
||||
raise BaseException("base exception should be raised")
|
||||
|
||||
@property
|
||||
def raise_exception(self):
|
||||
raise Exception("exception should be catched")
|
||||
|
||||
@property
|
||||
def raise_fail(self):
|
||||
def raise_fail_outcome(self):
|
||||
pytest.fail("fail should be catched")
|
||||
|
||||
|
||||
@@ -160,13 +164,15 @@ def test_helper_failures():
|
||||
with pytest.raises(Exception):
|
||||
helper.raise_exception
|
||||
with pytest.raises(OutcomeException):
|
||||
helper.raise_fail
|
||||
helper.raise_fail_outcome
|
||||
|
||||
|
||||
def test_safe_getattr():
|
||||
helper = ErrorsHelper()
|
||||
assert safe_getattr(helper, "raise_exception", "default") == "default"
|
||||
assert safe_getattr(helper, "raise_fail", "default") == "default"
|
||||
assert safe_getattr(helper, "raise_fail_outcome", "default") == "default"
|
||||
with pytest.raises(BaseException):
|
||||
assert safe_getattr(helper, "raise_baseexception", "default")
|
||||
|
||||
|
||||
def test_safe_isclass():
|
||||
|
||||
@@ -821,8 +821,15 @@ def test_pass_reporting_on_fail(testdir):
|
||||
def test_pass_output_reporting(testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def setup_module():
|
||||
print("setup_module")
|
||||
|
||||
def teardown_module():
|
||||
print("teardown_module")
|
||||
|
||||
def test_pass_has_output():
|
||||
print("Four score and seven years ago...")
|
||||
|
||||
def test_pass_no_output():
|
||||
pass
|
||||
"""
|
||||
@@ -837,8 +844,12 @@ def test_pass_output_reporting(testdir):
|
||||
[
|
||||
"*= PASSES =*",
|
||||
"*_ test_pass_has_output _*",
|
||||
"*- Captured stdout setup -*",
|
||||
"setup_module",
|
||||
"*- Captured stdout call -*",
|
||||
"Four score and seven years ago...",
|
||||
"*- Captured stdout teardown -*",
|
||||
"teardown_module",
|
||||
"*= short test summary info =*",
|
||||
"PASSED test_pass_output_reporting.py::test_pass_has_output",
|
||||
"PASSED test_pass_output_reporting.py::test_pass_no_output",
|
||||
|
||||
Reference in New Issue
Block a user