--fixtures only shows fixtures from first file

Fix #833
This commit is contained in:
Bruno Oliveira 2015-07-12 17:32:39 -03:00
parent 27a98788a8
commit 5ec2a17f08
3 changed files with 45 additions and 10 deletions

View File

@ -4,6 +4,11 @@
- preserve warning functions after call to pytest.deprecated_call. Thanks
Pieter Mulder for PR.
- fix issue833: --fixtures does not show fixtures defined in test files,
except for the first one collected. Thanks Florian Bruhin for reporting
and Bruno Oliveira for the PR.
2.7.2 (compared to 2.7.1)
-----------------------------
@ -27,7 +32,7 @@
Thanks Thomas De Schampheleire for reporting and Bruno Oliveira for the PR.
- fix issue718: failed to create representation of sets containing unsortable
elements in python 2. Thanks Edison Gustavo Muenz
elements in python 2. Thanks Edison Gustavo Muenz.
- fix issue756, fix issue752 (and similar issues): depend on py-1.4.29
which has a refined algorithm for traceback generation.

View File

@ -939,21 +939,13 @@ def showfixtures(config):
def _showfixtures_main(config, session):
session.perform_collect()
curdir = py.path.local()
if session.items:
nodeid = session.items[0].nodeid
else:
part = session._initialparts[0]
nodeid = "::".join(map(str, [curdir.bestrelpath(part[0])] + part[1:]))
nodeid.replace(session.fspath.sep, "/")
tw = py.io.TerminalWriter()
verbose = config.getvalue("verbose")
fm = session._fixturemanager
available = []
for argname in fm._arg2fixturedefs:
fixturedefs = fm.getfixturedefs(argname, nodeid)
for argname, fixturedefs in fm._arg2fixturedefs.items():
assert fixturedefs is not None
if not fixturedefs:
continue

View File

@ -2483,6 +2483,44 @@ class TestShowFixtures:
""")
def test_show_fixtures_different_files(self, testdir):
"""
#833: --fixtures only shows fixtures from first file
"""
testdir.makepyfile(test_a='''
import pytest
@pytest.fixture
def fix_a():
"""Fixture A"""
pass
def test_a(fix_a):
pass
''')
testdir.makepyfile(test_b='''
import pytest
@pytest.fixture
def fix_b():
"""Fixture B"""
pass
def test_b(fix_b):
pass
''')
result = testdir.runpytest("--fixtures")
result.stdout.fnmatch_lines("""
* fixtures defined from test_a *
fix_a
Fixture A
* fixtures defined from test_b *
fix_b
Fixture B
""")
class TestContextManagerFixtureFuncs:
def test_simple(self, testdir):
testdir.makepyfile("""