-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #3854 #3861
Fix #3854 #3861
Changes from 8 commits
d0bd01b
e4f76f6
4d3c1ab
5f8b50c
72e6482
3396225
459b040
e3df103
dce8df4
f0226e9
8cf0e46
1e4ecda
c336449
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
import textwrap | ||
|
||
import pytest | ||
|
@@ -3977,3 +3978,71 @@ def test_func(self, f2, f1, m2): | |
items, _ = testdir.inline_genitems() | ||
request = FixtureRequest(items[0]) | ||
assert request.fixturenames == "s1 p1 m1 m2 c1 f2 f1".split() | ||
|
||
def test_multiple_packages(self, testdir): | ||
"""Complex test involving multiple package fixtures. Make sure teardowns | ||
are executed in order. | ||
. | ||
└── root | ||
├── __init__.py | ||
├── sub1 | ||
│ ├── __init__.py | ||
│ ├── conftest.py | ||
│ └── test_1.py | ||
└── sub2 | ||
├── __init__.py | ||
├── conftest.py | ||
└── test_2.py | ||
""" | ||
root = testdir.mkdir("root") | ||
root.join("__init__.py").write("values = []") | ||
sub1 = root.mkdir("sub1") | ||
sub1.ensure("__init__.py") | ||
sub1.join("conftest.py").write( | ||
textwrap.dedent( | ||
"""\ | ||
import pytest | ||
from .. import values | ||
@pytest.fixture(scope="package") | ||
def fix(): | ||
values.append("pre-sub1") | ||
yield values | ||
values.pop() | ||
""" | ||
) | ||
) | ||
sub1.join("test_1.py").write( | ||
textwrap.dedent( | ||
"""\ | ||
from .. import values | ||
def test_1(fix): | ||
assert values == ["pre-sub1"] | ||
""" | ||
) | ||
) | ||
sub2 = root.mkdir("sub2") | ||
sub2.ensure("__init__.py") | ||
sub2.join("conftest.py").write( | ||
textwrap.dedent( | ||
"""\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid this weird line break by black I usually put the triple strings into a variable: contents = dedent("""\
...
""")
sub2.join("conftest.py").write(contents) But really up to you, just in case this bothers you. 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. black is going to reformat that to: contents = dedent(
"""\
...
"""
) :rip: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh. 😞 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can do this: x = """\
...
"""
print(dedent(x)) but then. meh. |
||
import pytest | ||
from .. import values | ||
@pytest.fixture(scope="package") | ||
def fix(): | ||
values.append("pre-sub2") | ||
yield values | ||
values.pop() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this should be assert values.pop() == "pre-sub2" for completeness? |
||
""" | ||
) | ||
) | ||
sub2.join("test_2.py").write( | ||
textwrap.dedent( | ||
"""\ | ||
from .. import values | ||
def test_2(fix): | ||
assert values == ["pre-sub2"] | ||
""" | ||
) | ||
) | ||
reprec = testdir.inline_run() | ||
reprec.assertoutcome(passed=2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should be
for completeness?