Skip to content

Commit fa3b631

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 222457d commit fa3b631

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

changelog/12749.feature.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Add :confval:`discover_imports`, when disabled (default) will make sure to not consider classes which are imported by a test file and starts with Test.
22

3-
-- by :user:`FreerGit`
3+
-- by :user:`FreerGit`

testing/test_discover_imports.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import pytest
1+
from __future__ import annotations
2+
23
import textwrap
34

5+
46
def test_discover_imports_enabled(pytester):
57
src_dir = pytester.mkdir("src")
68
tests_dir = pytester.mkdir("tests")
@@ -12,18 +14,21 @@ def test_discover_imports_enabled(pytester):
1214

1315
src_file = src_dir / "foo.py"
1416

15-
src_file.write_text(textwrap.dedent("""\
17+
src_file.write_text(
18+
textwrap.dedent("""\
1619
class TestClass(object):
1720
def __init__(self):
1821
super().__init__()
1922
2023
def test_foobar(self):
2124
return true
22-
"""
23-
), encoding="utf-8")
25+
"""),
26+
encoding="utf-8",
27+
)
2428

2529
test_file = tests_dir / "foo_test.py"
26-
test_file.write_text(textwrap.dedent("""\
30+
test_file.write_text(
31+
textwrap.dedent("""\
2732
import sys
2833
import os
2934
@@ -38,13 +43,15 @@ class TestDomain:
3843
def test_testament(self):
3944
testament = TestClass()
4045
pass
41-
"""), encoding="utf-8")
46+
"""),
47+
encoding="utf-8",
48+
)
4249

4350
result = pytester.runpytest()
4451
result.assert_outcomes(errors=1)
4552

53+
4654
def test_discover_imports_disabled(pytester):
47-
4855
src_dir = pytester.mkdir("src")
4956
tests_dir = pytester.mkdir("tests")
5057
pytester.makeini("""
@@ -55,19 +62,22 @@ def test_discover_imports_disabled(pytester):
5562

5663
src_file = src_dir / "foo.py"
5764

58-
src_file.write_text(textwrap.dedent("""\
65+
src_file.write_text(
66+
textwrap.dedent("""\
5967
class Testament(object):
6068
def __init__(self):
6169
super().__init__()
6270
self.collections = ["stamp", "coin"]
6371
6472
def personal_property(self):
6573
return [f"my {x} collection" for x in self.collections]
66-
"""
67-
), encoding="utf-8")
74+
"""),
75+
encoding="utf-8",
76+
)
6877

6978
test_file = tests_dir / "foo_test.py"
70-
test_file.write_text(textwrap.dedent("""\
79+
test_file.write_text(
80+
textwrap.dedent("""\
7181
import sys
7282
import os
7383
@@ -82,7 +92,9 @@ class TestDomain:
8292
def test_testament(self):
8393
testament = Testament()
8494
assert testament.personal_property()
85-
"""), encoding="utf-8")
95+
"""),
96+
encoding="utf-8",
97+
)
8698

8799
result = pytester.runpytest()
88-
result.assert_outcomes(passed=1)
100+
result.assert_outcomes(passed=1)

0 commit comments

Comments
 (0)