Skip to content

Commit 2a2293c

Browse files
committed
refactor(test): use the expected name for initializing tests.
Originally I used setup_test because something went wrong when I used setUp. I wrote pytest-dev/pytest#8424 about it. There they say to use `-p no:nose` to disable nose interpretation. But now I simply went back to setUp, and all seems well? Not sure what changed, but using the expected name is better.
1 parent 354245e commit 2a2293c

10 files changed

+26
-29
lines changed

pylintrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / stateme
148148
# TestCase overrides don't: setUp, tearDown
149149
# Nested decorator implementations: _decorator, _wrapper
150150
# Dispatched methods don't: _xxx__Xxxx
151-
no-docstring-rgx=__.*__|test[A-Z_].*|setup_test|_decorator|_wrapper|_.*__.*
151+
no-docstring-rgx=__.*__|test[A-Z_].*|setUp|_decorator|_wrapper|_.*__.*
152152

153153
# Regular expression which should only match correct module names
154154
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
@@ -236,7 +236,7 @@ additional-builtins=
236236
[CLASSES]
237237

238238
# List of method names used to declare (i.e. assign) instance attributes.
239-
defining-attr-methods=__init__,__new__,setup_test,reset
239+
defining-attr-methods=__init__,__new__,setUp,reset
240240

241241

242242
# checks for sign of poor/misdesign:

tests/coveragetest.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class CoverageTest(
5151
# Let stderr go to stderr, pytest will capture it for us.
5252
show_stderr = True
5353

54-
def setup_test(self):
55-
super().setup_test()
54+
def setUp(self):
55+
super().setUp()
5656

5757
# Attributes for getting info about what happened.
5858
self.last_command_status = None
@@ -455,8 +455,8 @@ def get_missing_arc_description(self, cov, start, end):
455455
class UsingModulesMixin:
456456
"""A mixin for importing modules from tests/modules and tests/moremodules."""
457457

458-
def setup_test(self):
459-
super().setup_test()
458+
def setUp(self):
459+
super().setUp()
460460

461461
# Parent class saves and restores sys.path, we can just modify it.
462462
sys.path.append(nice_file(TESTS_DIR, "modules"))

tests/mixins.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ def connect_to_pytest(self, request, monkeypatch):
2727
# pylint: disable=attribute-defined-outside-init
2828
self._pytest_request = request
2929
self._monkeypatch = monkeypatch
30-
self.setup_test()
30+
self.setUp()
3131

32-
# Can't call this setUp or setup because pytest sniffs out unittest and
33-
# nosetest special names, and does things with them.
34-
# https://github.com/pytest-dev/pytest/issues/8424
35-
def setup_test(self):
32+
def setUp(self):
3633
"""Per-test initialization. Override this as you wish."""
3734
pass
3835

tests/test_cmdline.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -940,8 +940,8 @@ def command_line(self, argv):
940940
raise AssertionError(f"Bad CoverageScriptStub: {argv!r}")
941941
return 0
942942

943-
def setup_test(self):
944-
super().setup_test()
943+
def setUp(self):
944+
super().setUp()
945945
old_CoverageScript = coverage.cmdline.CoverageScript
946946
coverage.cmdline.CoverageScript = self.CoverageScriptStub
947947
self.addCleanup(setattr, coverage.cmdline, 'CoverageScript', old_CoverageScript)

tests/test_files.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ def test_fnmatches_to_regex(patterns, case_insensitive, partial, matches, nomatc
144144
class MatcherTest(CoverageTest):
145145
"""Tests of file matchers."""
146146

147-
def setup_test(self):
148-
super().setup_test()
147+
def setUp(self):
148+
super().setUp()
149149
files.set_relative_directory()
150150

151151
def assertMatches(self, matcher, filepath, matches):

tests/test_goldtest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def path_regex(path):
4848
class CompareTest(CoverageTest):
4949
"""Tests of goldtest.py:compare()"""
5050

51-
def setup_test(self):
52-
super().setup_test()
51+
def setUp(self):
52+
super().setUp()
5353
self.addCleanup(remove_tree, ACTUAL_DIR)
5454

5555
def test_good(self):

tests/test_html.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def open(self, filename, mode="r"):
111111
class HtmlDeltaTest(HtmlTestHelpers, CoverageTest):
112112
"""Tests of the HTML delta speed-ups."""
113113

114-
def setup_test(self):
115-
super().setup_test()
114+
def setUp(self):
115+
super().setUp()
116116

117117
# At least one of our tests monkey-patches the version of coverage.py,
118118
# so grab it here to restore it later.

tests/test_numbits.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ class NumbitsSqliteFunctionTest(CoverageTest):
9898

9999
run_in_temp_dir = False
100100

101-
def setup_test(self):
102-
super().setup_test()
101+
def setUp(self):
102+
super().setUp()
103103
conn = sqlite3.connect(":memory:")
104104
register_sqlite_functions(conn)
105105
self.cursor = conn.cursor()

tests/test_process.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1236,8 +1236,8 @@ def test_pydoc_coverage_coverage(self):
12361236
class FailUnderTest(CoverageTest):
12371237
"""Tests of the --fail-under switch."""
12381238

1239-
def setup_test(self):
1240-
super().setup_test()
1239+
def setUp(self):
1240+
super().setUp()
12411241
self.make_file("forty_two_plus.py", """\
12421242
# I have 42.857% (3/7) coverage!
12431243
a = 1
@@ -1473,8 +1473,8 @@ def persistent_remove(path):
14731473
class ProcessCoverageMixin:
14741474
"""Set up a .pth file to coverage-measure all sub-processes."""
14751475

1476-
def setup_test(self):
1477-
super().setup_test()
1476+
def setUp(self):
1477+
super().setUp()
14781478

14791479
# Create the .pth file.
14801480
assert PTH_DIR
@@ -1490,8 +1490,8 @@ def setup_test(self):
14901490
class ProcessStartupTest(ProcessCoverageMixin, CoverageTest):
14911491
"""Test that we can measure coverage in sub-processes."""
14921492

1493-
def setup_test(self):
1494-
super().setup_test()
1493+
def setUp(self):
1494+
super().setUp()
14951495

14961496
# Main will run sub.py
14971497
self.make_file("main.py", """\

tests/test_setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class SetupPyTest(CoverageTest):
1515

1616
run_in_temp_dir = False
1717

18-
def setup_test(self):
19-
super().setup_test()
18+
def setUp(self):
19+
super().setUp()
2020
# Force the most restrictive interpretation.
2121
self.set_environ('LC_ALL', 'C')
2222

0 commit comments

Comments
 (0)