add feature to view fixture source location in invocations with --fixtures-per-test option (#8626)
* add feature to view fixture source location in invocations with --fixtures-per-test option * remove unrelated changes to show_fixtures_per_test::test_doctest_items * eshew the extraneous else in _show_fixtures_per_test.write_fixture * enable the accommodation of multi-line docstring with --fixtures-per-test option * add feature to view fixture source location in invocations with --fixtures * add colour encoding to fixture location paths * add changelog for #8606 fixing * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -29,7 +29,7 @@ def test_fixtures_in_module(pytester: Pytester) -> None:
|
||||
[
|
||||
"*fixtures used by test_arg1*",
|
||||
"*(test_fixtures_in_module.py:9)*",
|
||||
"arg1",
|
||||
"arg1 -- test_fixtures_in_module.py:6",
|
||||
" arg1 docstring",
|
||||
]
|
||||
)
|
||||
@@ -68,17 +68,16 @@ def test_fixtures_in_conftest(pytester: Pytester) -> None:
|
||||
[
|
||||
"*fixtures used by test_arg2*",
|
||||
"*(test_fixtures_in_conftest.py:2)*",
|
||||
"arg2",
|
||||
"arg2 -- conftest.py:6",
|
||||
" arg2 docstring",
|
||||
"*fixtures used by test_arg3*",
|
||||
"*(test_fixtures_in_conftest.py:4)*",
|
||||
"arg1",
|
||||
"arg1 -- conftest.py:3",
|
||||
" arg1 docstring",
|
||||
"arg2",
|
||||
"arg2 -- conftest.py:6",
|
||||
" arg2 docstring",
|
||||
"arg3",
|
||||
"arg3 -- conftest.py:9",
|
||||
" arg3",
|
||||
" docstring",
|
||||
]
|
||||
)
|
||||
|
||||
@@ -112,9 +111,9 @@ def test_should_show_fixtures_used_by_test(pytester: Pytester) -> None:
|
||||
[
|
||||
"*fixtures used by test_args*",
|
||||
"*(test_should_show_fixtures_used_by_test.py:6)*",
|
||||
"arg1",
|
||||
"arg1 -- test_should_show_fixtures_used_by_test.py:3",
|
||||
" arg1 from testmodule",
|
||||
"arg2",
|
||||
"arg2 -- conftest.py:6",
|
||||
" arg2 from conftest",
|
||||
]
|
||||
)
|
||||
@@ -181,3 +180,75 @@ def test_doctest_items(pytester: Pytester) -> None:
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines(["*collected 2 items*"])
|
||||
|
||||
|
||||
def test_multiline_docstring_in_module(pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
'''
|
||||
import pytest
|
||||
@pytest.fixture
|
||||
def arg1():
|
||||
"""Docstring content that spans across multiple lines,
|
||||
through second line,
|
||||
and through third line.
|
||||
|
||||
Docstring content that extends into a second paragraph.
|
||||
|
||||
Docstring content that extends into a third paragraph.
|
||||
"""
|
||||
def test_arg1(arg1):
|
||||
pass
|
||||
'''
|
||||
)
|
||||
|
||||
result = pytester.runpytest("--fixtures-per-test", p)
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*fixtures used by test_arg1*",
|
||||
"*(test_multiline_docstring_in_module.py:13)*",
|
||||
"arg1 -- test_multiline_docstring_in_module.py:3",
|
||||
" Docstring content that spans across multiple lines,",
|
||||
" through second line,",
|
||||
" and through third line.",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_verbose_include_multiline_docstring(pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
'''
|
||||
import pytest
|
||||
@pytest.fixture
|
||||
def arg1():
|
||||
"""Docstring content that spans across multiple lines,
|
||||
through second line,
|
||||
and through third line.
|
||||
|
||||
Docstring content that extends into a second paragraph.
|
||||
|
||||
Docstring content that extends into a third paragraph.
|
||||
"""
|
||||
def test_arg1(arg1):
|
||||
pass
|
||||
'''
|
||||
)
|
||||
|
||||
result = pytester.runpytest("--fixtures-per-test", "-v", p)
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*fixtures used by test_arg1*",
|
||||
"*(test_verbose_include_multiline_docstring.py:13)*",
|
||||
"arg1 -- test_verbose_include_multiline_docstring.py:3",
|
||||
" Docstring content that spans across multiple lines,",
|
||||
" through second line,",
|
||||
" and through third line.",
|
||||
" ",
|
||||
" Docstring content that extends into a second paragraph.",
|
||||
" ",
|
||||
" Docstring content that extends into a third paragraph.",
|
||||
]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user