From 5d6b0a59c0eb5a3c8a216bd6d88054c6b85b4210 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 4 Mar 2015 17:00:24 +0100 Subject: [PATCH] Strip docstrings in output with `--fixtures` Fixes https://bitbucket.org/pytest-dev/pytest/issue/550. --HG-- branch : strip-docstrings-from-fixtures --- _pytest/python.py | 2 +- testing/python/fixture.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index 183585302..8b32ccee1 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -979,7 +979,7 @@ def _showfixtures_main(config, session): loc = getlocation(fixturedef.func, curdir) doc = fixturedef.func.__doc__ or "" if doc: - for line in doc.split("\n"): + for line in doc.strip().split("\n"): tw.line(" " + line.strip()) else: tw.line(" %s: no docstring available" %(loc,), diff --git a/testing/python/fixture.py b/testing/python/fixture.py index 07fd0abcb..4d27fb1fa 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -500,7 +500,7 @@ class TestRequestBasic: reprec.assertoutcome(passed=3) def test_fixtures_sub_subdir_normalize_sep(self, testdir): - # this tests that normlization of nodeids takes place + # this tests that normalization of nodeids takes place b = testdir.mkdir("tests").mkdir("unit") b.join("conftest.py").write(py.code.Source(""" def pytest_funcarg__arg1(): @@ -2323,6 +2323,36 @@ class TestShowFixtures: *hello world* """) + def test_show_fixtures_trimmed_doc(self, testdir): + p = testdir.makepyfile(''' + import pytest + @pytest.fixture + def arg1(): + """ + line1 + line2 + + """ + @pytest.fixture + def arg2(): + """ + line1 + line2 + + """ + ''') + result = testdir.runpytest("--fixtures", p) + mark = dedent(""" + ------------- fixtures defined from test_show_fixtures_trimmed_doc ------------- + arg2 + line1 + line2 + arg1 + line1 + line2 + + """) + assert mark in result.stdout.str() class TestContextManagerFixtureFuncs: