Skip to content

Commit

Permalink
refactor(test): use the expected name for initializing tests.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nedbat committed Nov 7, 2021
1 parent 354245e commit 2a2293c
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 29 deletions.
4 changes: 2 additions & 2 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / stateme
# TestCase overrides don't: setUp, tearDown
# Nested decorator implementations: _decorator, _wrapper
# Dispatched methods don't: _xxx__Xxxx
no-docstring-rgx=__.*__|test[A-Z_].*|setup_test|_decorator|_wrapper|_.*__.*
no-docstring-rgx=__.*__|test[A-Z_].*|setUp|_decorator|_wrapper|_.*__.*

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

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


# checks for sign of poor/misdesign:
Expand Down
8 changes: 4 additions & 4 deletions tests/coveragetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class CoverageTest(
# Let stderr go to stderr, pytest will capture it for us.
show_stderr = True

def setup_test(self):
super().setup_test()
def setUp(self):
super().setUp()

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

def setup_test(self):
super().setup_test()
def setUp(self):
super().setUp()

# Parent class saves and restores sys.path, we can just modify it.
sys.path.append(nice_file(TESTS_DIR, "modules"))
Expand Down
7 changes: 2 additions & 5 deletions tests/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ def connect_to_pytest(self, request, monkeypatch):
# pylint: disable=attribute-defined-outside-init
self._pytest_request = request
self._monkeypatch = monkeypatch
self.setup_test()
self.setUp()

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

Expand Down
4 changes: 2 additions & 2 deletions tests/test_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,8 @@ def command_line(self, argv):
raise AssertionError(f"Bad CoverageScriptStub: {argv!r}")
return 0

def setup_test(self):
super().setup_test()
def setUp(self):
super().setUp()
old_CoverageScript = coverage.cmdline.CoverageScript
coverage.cmdline.CoverageScript = self.CoverageScriptStub
self.addCleanup(setattr, coverage.cmdline, 'CoverageScript', old_CoverageScript)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def test_fnmatches_to_regex(patterns, case_insensitive, partial, matches, nomatc
class MatcherTest(CoverageTest):
"""Tests of file matchers."""

def setup_test(self):
super().setup_test()
def setUp(self):
super().setUp()
files.set_relative_directory()

def assertMatches(self, matcher, filepath, matches):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_goldtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def path_regex(path):
class CompareTest(CoverageTest):
"""Tests of goldtest.py:compare()"""

def setup_test(self):
super().setup_test()
def setUp(self):
super().setUp()
self.addCleanup(remove_tree, ACTUAL_DIR)

def test_good(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def open(self, filename, mode="r"):
class HtmlDeltaTest(HtmlTestHelpers, CoverageTest):
"""Tests of the HTML delta speed-ups."""

def setup_test(self):
super().setup_test()
def setUp(self):
super().setUp()

# At least one of our tests monkey-patches the version of coverage.py,
# so grab it here to restore it later.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_numbits.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class NumbitsSqliteFunctionTest(CoverageTest):

run_in_temp_dir = False

def setup_test(self):
super().setup_test()
def setUp(self):
super().setUp()
conn = sqlite3.connect(":memory:")
register_sqlite_functions(conn)
self.cursor = conn.cursor()
Expand Down
12 changes: 6 additions & 6 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,8 +1236,8 @@ def test_pydoc_coverage_coverage(self):
class FailUnderTest(CoverageTest):
"""Tests of the --fail-under switch."""

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

def setup_test(self):
super().setup_test()
def setUp(self):
super().setUp()

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

def setup_test(self):
super().setup_test()
def setUp(self):
super().setUp()

# Main will run sub.py
self.make_file("main.py", """\
Expand Down
4 changes: 2 additions & 2 deletions tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class SetupPyTest(CoverageTest):

run_in_temp_dir = False

def setup_test(self):
super().setup_test()
def setUp(self):
super().setUp()
# Force the most restrictive interpretation.
self.set_environ('LC_ALL', 'C')

Expand Down

0 comments on commit 2a2293c

Please sign in to comment.