Organize tests into a class

This commit is contained in:
Patrick Lannigan 2023-12-02 19:52:53 -05:00
parent dc52beadc4
commit 61cc290f3e
No known key found for this signature in database
GPG Key ID: BBF5D9DED1E4AAF9
1 changed files with 108 additions and 116 deletions

View File

@ -2616,14 +2616,9 @@ def test_format_trimmed() -> None:
assert _format_trimmed(" ({}) ", msg, len(msg) + 3) == " (unconditional ...) "
def test_fine_grained_test_case_verbosity(pytester: Pytester) -> None:
p = pytester.makepyfile(_fine_grained_verbosity_file_contents())
pytester.makeini(
"""
[pytest]
verbosity_test_cases = 2
"""
)
class TestFineGrainedTestCase:
def test_max_verbosity(self, pytester: Pytester) -> None:
p = TestFineGrainedTestCase._initialize_files(pytester, verbosity=2)
result = pytester.runpytest(p)
result.stdout.fnmatch_lines(
@ -2634,22 +2629,15 @@ def test_fine_grained_test_case_verbosity(pytester: Pytester) -> None:
f"{p.name}::test_long_text_fail FAILED [ 57%]",
f"{p.name}::test_parametrize_fail[hello-1] FAILED [ 71%]",
f"{p.name}::test_parametrize_fail[world-987654321] FAILED [ 85%]",
f"{p.name}::test_sample_skip SKIPPED (some",
"long skip reason that will not fit on a single line with other content",
"that goes on and on and on and on and on) [100%]",
f"{p.name}::test_sample_skip SKIPPED (some long skip reason",
"that will not fit on a single line with other content that goes on and",
"on and on and on and on) [100%]",
],
consecutive=True,
)
def test_fine_grained_test_case_verbosity_collect_only_negative_2(pytester: Pytester) -> None:
p = pytester.makepyfile(_fine_grained_verbosity_file_contents())
pytester.makeini(
"""
[pytest]
verbosity_test_cases = -2
"""
)
def test_collect_only_negative_2(self, pytester: Pytester) -> None:
p = TestFineGrainedTestCase._initialize_files(pytester, verbosity=-2)
result = pytester.runpytest("--collect-only", p)
result.stdout.fnmatch_lines(
@ -2661,15 +2649,8 @@ def test_fine_grained_test_case_verbosity_collect_only_negative_2(pytester: Pyte
consecutive=True,
)
def test_fine_grained_test_case_verbosity_collect_only_positive_2(pytester: Pytester) -> None:
p = pytester.makepyfile(_fine_grained_verbosity_file_contents())
pytester.makeini(
"""
[pytest]
verbosity_test_cases = 2
"""
)
def test__collect_only_positive_2(self, pytester: Pytester) -> None:
p = TestFineGrainedTestCase._initialize_files(pytester, verbosity=2)
result = pytester.runpytest("--collect-only", p)
result.stdout.fnmatch_lines(
@ -2689,8 +2670,19 @@ def test_fine_grained_test_case_verbosity_collect_only_positive_2(pytester: Pyte
consecutive=True,
)
@staticmethod
def _initialize_files(pytester: Pytester, verbosity: int) -> Path:
p = pytester.makepyfile(TestFineGrainedTestCase.file_contents())
pytester.makeini(
f"""
[pytest]
verbosity_test_cases = {verbosity}
"""
)
return p
def _fine_grained_verbosity_file_contents() -> str:
@staticmethod
def file_contents() -> str:
long_text = "Lorem ipsum dolor sit amet " * 10
return f"""
import pytest