Skip to content

Fix: --fixtures only shows fixtures from first file #834

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

Merged
merged 2 commits into from
Jul 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
- preserve warning functions after call to pytest.deprecated_call. Thanks
Pieter Mulder for PR.

- fix issue833: --fixtures now shows all fixtures of collected test files, instead of just the
fixtures declared on the first one.
Thanks Florian Bruhin for reporting and Bruno Oliveira for the PR.


2.7.2 (compared to 2.7.1)
-----------------------------

Expand All @@ -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.
Expand Down
10 changes: 1 addition & 9 deletions _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions testing/python/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,44 @@ def arg2():
""")


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("""
Expand Down