From 20849a44f599ba48b4fafd198d5386f9bd42b1d4 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 17 Oct 2012 12:57:05 +0200 Subject: [PATCH] improve --fixtures output with per-plugin grouping and hiding underscore names in non-verbose mode, re-introduce --funcargs for compatibiliy --- _pytest/__init__.py | 2 +- _pytest/python.py | 17 +++++++++++++---- setup.py | 2 +- testing/test_python.py | 20 +++++++++++++++++++- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/_pytest/__init__.py b/_pytest/__init__.py index ec646814a..db2f0b9cb 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.3.0.dev25' +__version__ = '2.3.0.dev26' diff --git a/_pytest/python.py b/_pytest/python.py index aeba647f8..46d31755d 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -65,7 +65,7 @@ def pyobj_property(name): def pytest_addoption(parser): group = parser.getgroup("general") - group.addoption('--fixtures', '--fixtures', + group.addoption('--fixtures', '--funcargs', action="store_true", dest="showfixtures", default=False, help="show available fixtures, sorted by plugin appearance") parser.addini("usefixtures", type="args", default=[], @@ -746,15 +746,24 @@ def _showfixtures_main(config, session): fixturedef = fixturedefs[-1] loc = getlocation(fixturedef.func, curdir) available.append((len(fixturedef.baseid), + fixturedef.func.__module__, curdir.bestrelpath(loc), fixturedef.argname, fixturedef)) available.sort() - for baseid, bestrel, argname, fixturedef in available: + currentmodule = None + for baseid, module, bestrel, argname, fixturedef in available: + if currentmodule != module: + if not module.startswith("_pytest."): + tw.line() + tw.sep("-", "fixtures defined from %s" %(module,)) + currentmodule = module + if verbose <= 0 and argname[0] == "_": + continue if verbose > 0: - funcargspec = "%s -- %s" %(name, loc,) + funcargspec = "%s -- %s" %(argname, loc,) else: - funcargspec = argname # "%s %s" %(baseid, argname) + funcargspec = argname tw.line(funcargspec, green=True) loc = getlocation(fixturedef.func, curdir) doc = fixturedef.func.__doc__ or "" diff --git a/setup.py b/setup.py index 017c0b134..725609580 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.3.0.dev25', + version='2.3.0.dev26', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff --git a/testing/test_python.py b/testing/test_python.py index f737063c0..860b1db0f 100644 --- a/testing/test_python.py +++ b/testing/test_python.py @@ -1575,6 +1575,10 @@ class TestReportInfo: """ class TestShowFixtures: + def test_funcarg_compat(self, testdir): + config = testdir.parseconfigure("--funcargs") + assert config.option.showfixtures + def test_show_fixtures(self, testdir): result = testdir.runpytest("--fixtures") result.stdout.fnmatch_lines([ @@ -1583,19 +1587,32 @@ class TestShowFixtures: ] ) + def test_show_fixtures_verbose(self, testdir): + result = testdir.runpytest("--fixtures", "-v") + result.stdout.fnmatch_lines([ + "*tmpdir*", + "*temporary directory*", + ] + ) + def test_show_fixtures_testmodule(self, testdir): p = testdir.makepyfile(''' import pytest @pytest.fixture + def _arg0(): + """ hidden """ + @pytest.fixture def arg1(): """ hello world """ ''') result = testdir.runpytest("--fixtures", p) result.stdout.fnmatch_lines(""" - *tmpdir* + *tmpdir + *fixtures defined from* *arg1* *hello world* """) + assert "arg0" not in result.stdout.str() @pytest.mark.parametrize("testmod", [True, False]) def test_show_fixtures_conftest(self, testdir, testmod): @@ -1613,6 +1630,7 @@ class TestShowFixtures: result = testdir.runpytest("--fixtures") result.stdout.fnmatch_lines(""" *tmpdir* + *fixtures defined from*conftest* *arg1* *hello world* """)