2020-12-10 13:47:58 +08:00
|
|
|
from _pytest.pytester import Pytester
|
|
|
|
|
|
|
|
|
|
|
|
def test_no_items_should_not_show_output(pytester: Pytester) -> None:
|
|
|
|
result = pytester.runpytest("--fixtures-per-test")
|
2019-10-06 01:18:51 +08:00
|
|
|
result.stdout.no_fnmatch_line("*fixtures used by*")
|
2016-06-12 07:17:50 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_fixtures_in_module(pytester: Pytester) -> None:
|
|
|
|
p = pytester.makepyfile(
|
2016-06-12 07:17:50 +08:00
|
|
|
'''
|
|
|
|
import pytest
|
|
|
|
@pytest.fixture
|
|
|
|
def _arg0():
|
|
|
|
"""hidden arg0 fixture"""
|
|
|
|
@pytest.fixture
|
|
|
|
def arg1():
|
|
|
|
"""arg1 docstring"""
|
|
|
|
def test_arg1(arg1):
|
|
|
|
pass
|
|
|
|
'''
|
|
|
|
)
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
result = pytester.runpytest("--fixtures-per-test", p)
|
2016-06-12 07:17:50 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*fixtures used by test_arg1*",
|
2016-06-12 22:58:32 +08:00
|
|
|
"*(test_fixtures_in_module.py:9)*",
|
2021-05-14 20:38:55 +08:00
|
|
|
"arg1 -- test_fixtures_in_module.py:6",
|
2016-06-12 07:17:50 +08:00
|
|
|
" arg1 docstring",
|
|
|
|
]
|
|
|
|
)
|
2019-10-06 01:18:51 +08:00
|
|
|
result.stdout.no_fnmatch_line("*_arg0*")
|
2016-06-12 07:17:50 +08:00
|
|
|
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_fixtures_in_conftest(pytester: Pytester) -> None:
|
|
|
|
pytester.makeconftest(
|
2016-06-12 07:17:50 +08:00
|
|
|
'''
|
|
|
|
import pytest
|
|
|
|
@pytest.fixture
|
|
|
|
def arg1():
|
|
|
|
"""arg1 docstring"""
|
|
|
|
@pytest.fixture
|
|
|
|
def arg2():
|
|
|
|
"""arg2 docstring"""
|
|
|
|
@pytest.fixture
|
|
|
|
def arg3(arg1, arg2):
|
|
|
|
"""arg3
|
|
|
|
docstring
|
|
|
|
"""
|
|
|
|
'''
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
p = pytester.makepyfile(
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2016-06-12 07:17:50 +08:00
|
|
|
def test_arg2(arg2):
|
|
|
|
pass
|
|
|
|
def test_arg3(arg3):
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2016-06-12 07:17:50 +08:00
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
result = pytester.runpytest("--fixtures-per-test", p)
|
2016-06-12 07:17:50 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*fixtures used by test_arg2*",
|
2016-06-12 22:58:32 +08:00
|
|
|
"*(test_fixtures_in_conftest.py:2)*",
|
2021-05-14 20:38:55 +08:00
|
|
|
"arg2 -- conftest.py:6",
|
2016-06-12 07:17:50 +08:00
|
|
|
" arg2 docstring",
|
|
|
|
"*fixtures used by test_arg3*",
|
2016-06-12 22:58:32 +08:00
|
|
|
"*(test_fixtures_in_conftest.py:4)*",
|
2021-05-14 20:38:55 +08:00
|
|
|
"arg1 -- conftest.py:3",
|
2016-06-12 07:17:50 +08:00
|
|
|
" arg1 docstring",
|
2021-05-14 20:38:55 +08:00
|
|
|
"arg2 -- conftest.py:6",
|
2016-06-12 07:17:50 +08:00
|
|
|
" arg2 docstring",
|
2021-05-14 20:38:55 +08:00
|
|
|
"arg3 -- conftest.py:9",
|
2016-06-12 07:17:50 +08:00
|
|
|
" arg3",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_should_show_fixtures_used_by_test(pytester: Pytester) -> None:
|
|
|
|
pytester.makeconftest(
|
2016-06-12 07:17:50 +08:00
|
|
|
'''
|
|
|
|
import pytest
|
|
|
|
@pytest.fixture
|
|
|
|
def arg1():
|
|
|
|
"""arg1 from conftest"""
|
|
|
|
@pytest.fixture
|
|
|
|
def arg2():
|
|
|
|
"""arg2 from conftest"""
|
|
|
|
'''
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
p = pytester.makepyfile(
|
2016-06-12 07:17:50 +08:00
|
|
|
'''
|
|
|
|
import pytest
|
|
|
|
@pytest.fixture
|
|
|
|
def arg1():
|
|
|
|
"""arg1 from testmodule"""
|
|
|
|
def test_args(arg1, arg2):
|
|
|
|
pass
|
|
|
|
'''
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
result = pytester.runpytest("--fixtures-per-test", p)
|
2016-06-12 07:17:50 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*fixtures used by test_args*",
|
2016-06-12 22:58:32 +08:00
|
|
|
"*(test_should_show_fixtures_used_by_test.py:6)*",
|
2021-05-14 20:38:55 +08:00
|
|
|
"arg1 -- test_should_show_fixtures_used_by_test.py:3",
|
2016-06-12 07:17:50 +08:00
|
|
|
" arg1 from testmodule",
|
2021-05-14 20:38:55 +08:00
|
|
|
"arg2 -- conftest.py:6",
|
2016-06-12 07:17:50 +08:00
|
|
|
" arg2 from conftest",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_verbose_include_private_fixtures_and_loc(pytester: Pytester) -> None:
|
|
|
|
pytester.makeconftest(
|
2016-06-12 07:17:50 +08:00
|
|
|
'''
|
|
|
|
import pytest
|
|
|
|
@pytest.fixture
|
|
|
|
def _arg1():
|
|
|
|
"""_arg1 from conftest"""
|
|
|
|
@pytest.fixture
|
|
|
|
def arg2(_arg1):
|
|
|
|
"""arg2 from conftest"""
|
|
|
|
'''
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
p = pytester.makepyfile(
|
2016-06-12 07:17:50 +08:00
|
|
|
'''
|
|
|
|
import pytest
|
|
|
|
@pytest.fixture
|
|
|
|
def arg3():
|
|
|
|
"""arg3 from testmodule"""
|
|
|
|
def test_args(arg2, arg3):
|
|
|
|
pass
|
|
|
|
'''
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
result = pytester.runpytest("--fixtures-per-test", "-v", p)
|
2016-06-12 07:17:50 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*fixtures used by test_args*",
|
2016-06-12 22:58:32 +08:00
|
|
|
"*(test_verbose_include_private_fixtures_and_loc.py:6)*",
|
2016-06-12 07:17:50 +08:00
|
|
|
"_arg1 -- conftest.py:3",
|
|
|
|
" _arg1 from conftest",
|
|
|
|
"arg2 -- conftest.py:6",
|
|
|
|
" arg2 from conftest",
|
|
|
|
"arg3 -- test_verbose_include_private_fixtures_and_loc.py:3",
|
|
|
|
" arg3 from testmodule",
|
|
|
|
]
|
|
|
|
)
|
2017-09-19 18:41:12 +08:00
|
|
|
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_doctest_items(pytester: Pytester) -> None:
|
|
|
|
pytester.makepyfile(
|
2017-09-19 18:41:12 +08:00
|
|
|
'''
|
|
|
|
def foo():
|
|
|
|
"""
|
|
|
|
>>> 1 + 1
|
|
|
|
2
|
|
|
|
"""
|
|
|
|
'''
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
pytester.maketxtfile(
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2017-09-19 18:41:12 +08:00
|
|
|
>>> 1 + 1
|
|
|
|
2
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2017-09-19 18:41:12 +08:00
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
result = pytester.runpytest(
|
2017-09-19 18:41:12 +08:00
|
|
|
"--fixtures-per-test", "--doctest-modules", "--doctest-glob=*.txt", "-v"
|
|
|
|
)
|
|
|
|
assert result.ret == 0
|
|
|
|
|
|
|
|
result.stdout.fnmatch_lines(["*collected 2 items*"])
|
2021-05-14 20:38:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
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.",
|
|
|
|
]
|
|
|
|
)
|