Skip to content

Commit c5d26ae

Browse files
committed
Merge pull request #834 from nicoddemus/show-fixtures-bug
Fix: --fixtures only shows fixtures from first file
2 parents 27a9878 + 5750ae7 commit c5d26ae

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

CHANGELOG

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
- preserve warning functions after call to pytest.deprecated_call. Thanks
55
Pieter Mulder for PR.
66

7+
- fix issue833: --fixtures now shows all fixtures of collected test files, instead of just the
8+
fixtures declared on the first one.
9+
Thanks Florian Bruhin for reporting and Bruno Oliveira for the PR.
10+
11+
712
2.7.2 (compared to 2.7.1)
813
-----------------------------
914

@@ -27,7 +32,7 @@
2732
Thanks Thomas De Schampheleire for reporting and Bruno Oliveira for the PR.
2833

2934
- fix issue718: failed to create representation of sets containing unsortable
30-
elements in python 2. Thanks Edison Gustavo Muenz
35+
elements in python 2. Thanks Edison Gustavo Muenz.
3136

3237
- fix issue756, fix issue752 (and similar issues): depend on py-1.4.29
3338
which has a refined algorithm for traceback generation.

_pytest/python.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -939,21 +939,13 @@ def showfixtures(config):
939939
def _showfixtures_main(config, session):
940940
session.perform_collect()
941941
curdir = py.path.local()
942-
if session.items:
943-
nodeid = session.items[0].nodeid
944-
else:
945-
part = session._initialparts[0]
946-
nodeid = "::".join(map(str, [curdir.bestrelpath(part[0])] + part[1:]))
947-
nodeid.replace(session.fspath.sep, "/")
948-
949942
tw = py.io.TerminalWriter()
950943
verbose = config.getvalue("verbose")
951944

952945
fm = session._fixturemanager
953946

954947
available = []
955-
for argname in fm._arg2fixturedefs:
956-
fixturedefs = fm.getfixturedefs(argname, nodeid)
948+
for argname, fixturedefs in fm._arg2fixturedefs.items():
957949
assert fixturedefs is not None
958950
if not fixturedefs:
959951
continue

testing/python/fixture.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,6 +2483,44 @@ def arg2():
24832483
""")
24842484

24852485

2486+
def test_show_fixtures_different_files(self, testdir):
2487+
"""
2488+
#833: --fixtures only shows fixtures from first file
2489+
"""
2490+
testdir.makepyfile(test_a='''
2491+
import pytest
2492+
2493+
@pytest.fixture
2494+
def fix_a():
2495+
"""Fixture A"""
2496+
pass
2497+
2498+
def test_a(fix_a):
2499+
pass
2500+
''')
2501+
testdir.makepyfile(test_b='''
2502+
import pytest
2503+
2504+
@pytest.fixture
2505+
def fix_b():
2506+
"""Fixture B"""
2507+
pass
2508+
2509+
def test_b(fix_b):
2510+
pass
2511+
''')
2512+
result = testdir.runpytest("--fixtures")
2513+
result.stdout.fnmatch_lines("""
2514+
* fixtures defined from test_a *
2515+
fix_a
2516+
Fixture A
2517+
2518+
* fixtures defined from test_b *
2519+
fix_b
2520+
Fixture B
2521+
""")
2522+
2523+
24862524
class TestContextManagerFixtureFuncs:
24872525
def test_simple(self, testdir):
24882526
testdir.makepyfile("""

0 commit comments

Comments
 (0)