Skip to content

Commit 21622d0

Browse files
committed
Merge remote-tracking branch 'upstream/master' into release-5.3.0
2 parents d1e2d12 + f36ea24 commit 21622d0

File tree

9 files changed

+109
-7
lines changed

9 files changed

+109
-7
lines changed

AUTHORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Jordan Guymon
135135
Jordan Moldow
136136
Jordan Speicher
137137
Joseph Hunkeler
138+
Josh Karpel
138139
Joshua Bronson
139140
Jurko Gospodnetić
140141
Justyna Janczyszyn
@@ -264,6 +265,7 @@ Virgil Dupras
264265
Vitaly Lashmanov
265266
Vlad Dragos
266267
Volodymyr Piskun
268+
Wei Lin
267269
Wil Cooley
268270
William Lee
269271
Wim Glenn

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,8 @@ Features
19011901
live-logging is enabled and/or when they are logged to a file.
19021902

19031903

1904-
- `#3985 <https://github.com/pytest-dev/pytest/issues/3985>`_: Introduce ``tmp_path`` as a fixture providing a Path object.
1904+
- `#3985 <https://github.com/pytest-dev/pytest/issues/3985>`_: Introduce ``tmp_path`` as a fixture providing a Path object. Also introduce ``tmp_path_factory`` as
1905+
a session-scoped fixture for creating arbitrary temporary directories from any other fixture or test.
19051906

19061907

19071908
- `#4013 <https://github.com/pytest-dev/pytest/issues/4013>`_: Deprecation warnings are now shown even if you customize the warnings filters yourself. In the previous version

changelog/2049.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix ``-setup-plan`` showing inaccurate information about fixture lifetimes.

changelog/6189.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix incorrect result of ``getmodpath`` method.

src/_pytest/python.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ def getmodpath(self, stopatmodule=True, includemodule=False):
287287
break
288288
parts.append(name)
289289
parts.reverse()
290-
s = ".".join(parts)
291-
return s.replace(".[", "[")
290+
return ".".join(parts)
292291

293292
def reportinfo(self) -> Tuple[str, int, str]:
294293
# XXX caching?

src/_pytest/setupplan.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def pytest_addoption(parser):
1616
def pytest_fixture_setup(fixturedef, request):
1717
# Will return a dummy fixture if the setuponly option is provided.
1818
if request.config.option.setupplan:
19-
fixturedef.cached_result = (None, None, None)
19+
my_cache_key = fixturedef.cache_key(request)
20+
fixturedef.cached_result = (None, my_cache_key, None)
2021
return fixturedef.cached_result
2122

2223

testing/acceptance_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,6 @@ def test():
760760
result = testdir.runpytest(str(p) + "::test", "--doctest-modules")
761761
result.stdout.fnmatch_lines(["*1 passed*"])
762762

763-
@pytest.mark.skipif(not hasattr(os, "symlink"), reason="requires symlinks")
764763
def test_cmdline_python_package_symlink(self, testdir, monkeypatch):
765764
"""
766765
test --pyargs option with packages with path containing symlink can

testing/test_collection.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,8 @@ def test_2():
685685
def test_example_items1(self, testdir):
686686
p = testdir.makepyfile(
687687
"""
688+
import pytest
689+
688690
def testone():
689691
pass
690692
@@ -693,19 +695,24 @@ def testmethod_one(self):
693695
pass
694696
695697
class TestY(TestX):
696-
pass
698+
@pytest.mark.parametrize("arg0", [".["])
699+
def testmethod_two(self, arg0):
700+
pass
697701
"""
698702
)
699703
items, reprec = testdir.inline_genitems(p)
700-
assert len(items) == 3
704+
assert len(items) == 4
701705
assert items[0].name == "testone"
702706
assert items[1].name == "testmethod_one"
703707
assert items[2].name == "testmethod_one"
708+
assert items[3].name == "testmethod_two[.[]"
704709

705710
# let's also test getmodpath here
706711
assert items[0].getmodpath() == "testone"
707712
assert items[1].getmodpath() == "TestX.testmethod_one"
708713
assert items[2].getmodpath() == "TestY.testmethod_one"
714+
# PR #6202: Fix incorrect result of getmodpath method. (Resolves issue #6189)
715+
assert items[3].getmodpath() == "TestY.testmethod_two[.[]"
709716

710717
s = items[0].getmodpath(stopatmodule=False)
711718
assert s.endswith("test_example_items1.testone")

testing/test_setupplan.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,94 @@ def test_arg(arg):
1717
result.stdout.fnmatch_lines(
1818
["*SETUP F arg*", "*test_arg (fixtures used: arg)", "*TEARDOWN F arg*"]
1919
)
20+
21+
22+
def test_show_multi_test_fixture_setup_and_teardown_correctly_simple(testdir):
23+
"""
24+
Verify that when a fixture lives for longer than a single test, --setup-plan
25+
correctly displays the SETUP/TEARDOWN indicators the right number of times.
26+
27+
As reported in https://github.com/pytest-dev/pytest/issues/2049
28+
--setup-plan was showing SETUP/TEARDOWN on every test, even when the fixture
29+
should persist through multiple tests.
30+
31+
(Note that this bug never affected actual test execution, which used the
32+
correct fixture lifetimes. It was purely a display bug for --setup-plan, and
33+
did not affect the related --setup-show or --setup-only.)
34+
"""
35+
testdir.makepyfile(
36+
"""
37+
import pytest
38+
@pytest.fixture(scope = 'class')
39+
def fix():
40+
return object()
41+
class TestClass:
42+
def test_one(self, fix):
43+
assert False
44+
def test_two(self, fix):
45+
assert False
46+
"""
47+
)
48+
49+
result = testdir.runpytest("--setup-plan")
50+
assert result.ret == 0
51+
52+
setup_fragment = "SETUP C fix"
53+
setup_count = 0
54+
55+
teardown_fragment = "TEARDOWN C fix"
56+
teardown_count = 0
57+
58+
for line in result.stdout.lines:
59+
if setup_fragment in line:
60+
setup_count += 1
61+
if teardown_fragment in line:
62+
teardown_count += 1
63+
64+
# before the fix this tests, there would have been a setup/teardown
65+
# message for each test, so the counts would each have been 2
66+
assert setup_count == 1
67+
assert teardown_count == 1
68+
69+
70+
def test_show_multi_test_fixture_setup_and_teardown_same_as_setup_show(testdir):
71+
"""
72+
Verify that SETUP/TEARDOWN messages match what comes out of --setup-show.
73+
"""
74+
testdir.makepyfile(
75+
"""
76+
import pytest
77+
@pytest.fixture(scope = 'session')
78+
def sess():
79+
return True
80+
@pytest.fixture(scope = 'module')
81+
def mod():
82+
return True
83+
@pytest.fixture(scope = 'class')
84+
def cls():
85+
return True
86+
@pytest.fixture(scope = 'function')
87+
def func():
88+
return True
89+
def test_outside(sess, mod, cls, func):
90+
assert True
91+
class TestCls:
92+
def test_one(self, sess, mod, cls, func):
93+
assert True
94+
def test_two(self, sess, mod, cls, func):
95+
assert True
96+
"""
97+
)
98+
99+
plan_result = testdir.runpytest("--setup-plan")
100+
show_result = testdir.runpytest("--setup-show")
101+
102+
# the number and text of these lines should be identical
103+
plan_lines = [
104+
l for l in plan_result.stdout.lines if "SETUP" in l or "TEARDOWN" in l
105+
]
106+
show_lines = [
107+
l for l in show_result.stdout.lines if "SETUP" in l or "TEARDOWN" in l
108+
]
109+
110+
assert plan_lines == show_lines

0 commit comments

Comments
 (0)