From 5ec2a17f08f3fa51a32607b174c96b5801d39551 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 12 Jul 2015 17:32:39 -0300 Subject: [PATCH] --fixtures only shows fixtures from first file Fix #833 --- CHANGELOG | 7 ++++++- _pytest/python.py | 10 +--------- testing/python/fixture.py | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9484b0b75..7d48d5444 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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. diff --git a/_pytest/python.py b/_pytest/python.py index 2fa4af373..052a07784 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -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 diff --git a/testing/python/fixture.py b/testing/python/fixture.py index ef43744d5..69c140f8d 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -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("""