forked from smarie/python-pytest-cases
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_issue_374.py
More file actions
91 lines (63 loc) · 1.98 KB
/
Copy pathtest_issue_374.py
File metadata and controls
91 lines (63 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
OVERRIDDEN_FIXTURES_TEST_FILE = """
import pytest
@pytest.fixture
def db(): pass
@pytest.fixture
def app(db): pass
# See https://github.com/pytest-dev/pytest/issues/13773
# Issue occurred in collection with Pytest 9+
class TestOverrideWithParent:
# Overrides module-level app, doesn't request `db` directly, only transitively.
@pytest.fixture
def app(self, app): pass
def test_something(self, app): pass
class TestOverrideWithoutParent:
# Overrides module-level app, doesn't request `db` at all.
@pytest.fixture
def app(self): pass
def test_something(self, app): pass
"""
def test_overridden_fixtures(pytester):
pytester.makepyfile(OVERRIDDEN_FIXTURES_TEST_FILE)
result = pytester.runpytest()
result.assert_outcomes(passed=2)
# Using union fixtures.
OVERRIDDEN_UNION_FIXTURES_TEST_FILE = """
import pytest
from pytest_cases import parametrize, parametrize_with_cases, case, fixture
@fixture
def db(): pass
@fixture
def app(db): pass
def case_hello():
return "hello !"
@fixture
def surname():
return "joe"
@fixture
@parametrize("_name", ["you", "earthling"])
def name(_name, surname, app):
return f"{_name} {surname}"
@case(id="hello_fixture")
def case_basic3(name):
return "hello, %s !" % name
class TestOverrideWithParent:
# Overrides module-level name, doesn't request `name` directly, only transitively.
@fixture
def name(self, name):
return "overridden %s" % name
@parametrize_with_cases("msg", cases=".")
def test_something(self, msg): pass
class TestOverrideWithoutParent:
# Overrides module-level name, doesn't request name at all
@fixture
@parametrize("_name", ["hi", "martian"])
def name(self, _name):
return _name
@parametrize_with_cases("msg", cases=".")
def test_something(self, msg): pass
"""
def test_overridden_unions(pytester):
pytester.makepyfile(OVERRIDDEN_UNION_FIXTURES_TEST_FILE)
result = pytester.runpytest()
result.assert_outcomes(passed=6)