diff --git a/_pytest/__init__.py b/_pytest/__init__.py index 48afb1496..7da3bfaab 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.3.0.dev20' +__version__ = '2.3.0.dev21' diff --git a/_pytest/python.py b/_pytest/python.py index cf1c9217b..ea4ba5c48 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -742,37 +742,45 @@ def showfixtures(config): def _showfixtures_main(config, session): session.perform_collect() - if session.items: - plugins = session.items[0].getplugins() - else: - plugins = session.getplugins() 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:])) + tw = py.io.TerminalWriter() verbose = config.getvalue("verbose") - argprefix = session._fixturemanager._argprefix - for plugin in plugins: - available = [] - for name, factory in vars(plugin).items(): - if name.startswith(argprefix): - name = name[len(argprefix):] - if name not in available: - available.append([name, factory]) - if available: - pluginname = plugin.__name__ - for name, factory in available: - loc = getlocation(factory, curdir) - if verbose > 0: - funcargspec = "%s -- %s" %(name, loc,) - else: - funcargspec = name - tw.line(funcargspec, green=True) - doc = factory.__doc__ or "" - if doc: - for line in doc.split("\n"): - tw.line(" " + line.strip()) - else: - tw.line(" %s: no docstring available" %(loc,), - red=True) + + fm = session._fixturemanager + + available = [] + for argname in fm.arg2fixturedeflist: + fixturedeflist = fm.getfixturedeflist(argname, nodeid) + assert fixturedeflist is not None + if not fixturedeflist: + continue + fixturedef = fixturedeflist[-1] + loc = getlocation(fixturedef.func, curdir) + available.append((len(fixturedef.baseid), + curdir.bestrelpath(loc), + fixturedef.argname, fixturedef)) + + available.sort() + for baseid, bestrel, argname, fixturedef in available: + if verbose > 0: + funcargspec = "%s -- %s" %(name, loc,) + else: + funcargspec = argname # "%s %s" %(baseid, argname) + tw.line(funcargspec, green=True) + loc = getlocation(fixturedef.func, curdir) + doc = fixturedef.func.__doc__ or "" + if doc: + for line in doc.split("\n"): + tw.line(" " + line.strip()) + else: + tw.line(" %s: no docstring available" %(loc,), + red=True) def getlocation(function, curdir): import inspect diff --git a/doc/en/Makefile b/doc/en/Makefile index 9de7a8ba8..9c99438c6 100644 --- a/doc/en/Makefile +++ b/doc/en/Makefile @@ -43,7 +43,7 @@ install: html rsync -avz _build/html/ pytest.org:/www/pytest.org/dev installpdf: latexpdf - @scp $(BUILDDIR)/latex/pytest.pdf pytest.org:/www/pytest.org/latest + @scp $(BUILDDIR)/latex/pytest.pdf pytest.org:/www/pytest.org/dev installall: clean install installpdf @echo "done" diff --git a/setup.py b/setup.py index 3b5a053a0..691f02210 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.dev20', + version='2.3.0.dev21', 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 7c09a216c..bf109b780 100644 --- a/testing/test_python.py +++ b/testing/test_python.py @@ -1515,13 +1515,50 @@ class TestReportInfo: pass """ -def test_show_funcarg(testdir): - result = testdir.runpytest("--fixtures") - result.stdout.fnmatch_lines([ - "*tmpdir*", - "*temporary directory*", - ] - ) +class TestShowFixtures: + def test_show_fixtures(self, testdir): + result = testdir.runpytest("--fixtures") + result.stdout.fnmatch_lines([ + "*tmpdir*", + "*temporary directory*", + ] + ) + + def test_show_fixtures_testmodule(self, testdir): + p = testdir.makepyfile(''' + import pytest + @pytest.fixture + def arg1(): + """ hello world """ + ''') + result = testdir.runpytest("--fixtures", p) + result.stdout.fnmatch_lines(""" + *tmpdir* + *arg1* + *hello world* + """) + + @pytest.mark.parametrize("testmod", [True, False]) + def test_show_fixtures_conftest(self, testdir, testmod): + testdir.makeconftest(''' + import pytest + @pytest.fixture + def arg1(): + """ hello world """ + ''') + if testmod: + testdir.makepyfile(""" + def test_hello(): + pass + """) + result = testdir.runpytest("--fixtures") + result.stdout.fnmatch_lines(""" + *tmpdir* + *arg1* + *hello world* + """) + + class TestRaises: def test_raises(self):