summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-02-06 21:55:29 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-02-06 21:57:26 -0500
commit2af7e87b26754fea68adfd1b8aa51052d987e60c (patch)
tree3d81d1e79bebd529240629b9cd43c4f0e273046b
parente59da1bafafe4265188bb5c75c4e557dfbd47d90 (diff)
downloadpython-coveragepy-git-nedbat/better-combine-action.tar.gz
refactor: convert all skipping to pytest skipsnedbat/better-combine-action
-rw-r--r--tests/coveragetest.py2
-rw-r--r--tests/test_api.py8
-rw-r--r--tests/test_arcs.py16
-rw-r--r--tests/test_cmdline.py6
-rw-r--r--tests/test_concurrency.py7
-rw-r--r--tests/test_context.py5
-rw-r--r--tests/test_coverage.py7
-rw-r--r--tests/test_execfile.py2
-rw-r--r--tests/test_files.py6
-rw-r--r--tests/test_oddball.py16
-rw-r--r--tests/test_phystokens.py6
-rw-r--r--tests/test_plugins.py10
-rw-r--r--tests/test_process.py56
-rw-r--r--tests/test_summary.py13
14 files changed, 53 insertions, 107 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index 69dbb7cf..8e5f2b0a 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -389,7 +389,7 @@ class CoverageTest(
if env.JYTHON: # pragma: only jython
# Jython can't do reporting, so let's skip the test now.
if command_args and command_args[0] in ('report', 'html', 'xml', 'annotate'):
- self.skipTest("Can't run reporting commands in Jython")
+ pytest.skip("Can't run reporting commands in Jython")
# Jython can't run "coverage" as a command because the shebang
# refers to another shebang'd Python script. So run them as
# modules.
diff --git a/tests/test_api.py b/tests/test_api.py
index 0c1c9035..66f471c3 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -763,14 +763,12 @@ class CurrentInstanceTest(CoverageTest):
assert cur0 is cur3
+@pytest.mark.skip(not env.PYBEHAVIOR.namespaces_pep420,
+ reason="Python before 3.3 doesn't have namespace packages"
+)
class NamespaceModuleTest(UsingModulesMixin, CoverageTest):
"""Test PEP-420 namespace modules."""
- def setUp(self):
- if not env.PYBEHAVIOR.namespaces_pep420:
- self.skipTest("Python before 3.3 doesn't have namespace packages")
- super(NamespaceModuleTest, self).setUp()
-
def test_explicit_namespace_module(self):
self.make_file("main.py", "import namespace_420\n")
diff --git a/tests/test_arcs.py b/tests/test_arcs.py
index c6cf7952..83e9e6b1 100644
--- a/tests/test_arcs.py
+++ b/tests/test_arcs.py
@@ -1085,9 +1085,10 @@ class YieldTest(CoverageTest):
)
assert self.stdout() == "20\n12\n"
+ @pytest.mark.skipif(not env.PYBEHAVIOR.yield_from,
+ reason="Python before 3.3 doesn't have 'yield from'"
+ )
def test_yield_from(self):
- if not env.PYBEHAVIOR.yield_from:
- self.skipTest("Python before 3.3 doesn't have 'yield from'")
self.check_coverage("""\
def gen(inp):
i = 2
@@ -1332,9 +1333,10 @@ class MiscArcTest(CoverageTest):
arcz=".1 19 9.",
)
+ @pytest.mark.skipif(not env.PYBEHAVIOR.unpackings_pep448,
+ reason="Don't have unpacked literals until 3.5"
+ )
def test_unpacked_literals(self):
- if not env.PYBEHAVIOR.unpackings_pep448:
- self.skipTest("Don't have unpacked literals until 3.5")
self.check_coverage("""\
d = {
'a': 2,
@@ -1581,14 +1583,10 @@ class LambdaArcTest(CoverageTest):
)
+@pytest.mark.skipif(not env.PYBEHAVIOR.async_syntax, reason="Async features are new in Python 3.5")
class AsyncTest(CoverageTest):
"""Tests of the new async and await keywords in Python 3.5"""
- def setUp(self):
- if not env.PYBEHAVIOR.async_syntax:
- self.skipTest("Async features are new in Python 3.5")
- super(AsyncTest, self).setUp()
-
def test_async(self):
self.check_coverage("""\
import asyncio
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 0eb26cd0..d5141028 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -816,10 +816,9 @@ class CmdLineStdoutTest(BaseCmdLineTest):
assert "without C extension" in out
assert out.count("\n") < 4
+ @pytest.mark.skipif(env.JYTHON, reason="Jython gets mad if you patch sys.argv")
def test_help_contains_command_name(self):
# Command name should be present in help output.
- if env.JYTHON:
- self.skipTest("Jython gets mad if you patch sys.argv")
fake_command_path = "lorem/ipsum/dolor".replace("/", os.sep)
expected_command_name = "dolor"
fake_argv = [fake_command_path, "sit", "amet"]
@@ -828,6 +827,7 @@ class CmdLineStdoutTest(BaseCmdLineTest):
out = self.stdout()
assert expected_command_name in out
+ @pytest.mark.skipif(env.JYTHON, reason="Jython gets mad if you patch sys.argv")
def test_help_contains_command_name_from_package(self):
# Command package name should be present in help output.
#
@@ -835,8 +835,6 @@ class CmdLineStdoutTest(BaseCmdLineTest):
# has the `__main__.py` file's patch as the command name. Instead, the command name should
# be derived from the package name.
- if env.JYTHON:
- self.skipTest("Jython gets mad if you patch sys.argv")
fake_command_path = "lorem/ipsum/dolor/__main__.py".replace("/", os.sep)
expected_command_name = "dolor"
fake_argv = [fake_command_path, "sit", "amet"]
diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py
index fd7aa851..86c69cf5 100644
--- a/tests/test_concurrency.py
+++ b/tests/test_concurrency.py
@@ -12,6 +12,7 @@ import threading
import time
from flaky import flaky
+import pytest
import coverage
from coverage import env
@@ -363,15 +364,11 @@ MULTI_CODE = """
"""
+@pytest.mark.skipif(not multiprocessing, reason="No multiprocessing in this Python")
@flaky(max_runs=30) # Sometimes a test fails due to inherent randomness. Try more times.
class MultiprocessingTest(CoverageTest):
"""Test support of the multiprocessing module."""
- def setUp(self):
- if not multiprocessing:
- self.skipTest("No multiprocessing in this Python") # pragma: only jython
- super(MultiprocessingTest, self).setUp()
-
def try_multiprocessing_code(
self, code, expected_out, the_module, nprocs, concurrency="multiprocessing", args=""
):
diff --git a/tests/test_context.py b/tests/test_context.py
index 20b7a290..f51befae 100644
--- a/tests/test_context.py
+++ b/tests/test_context.py
@@ -6,6 +6,8 @@
import inspect
import os.path
+import pytest
+
import coverage
from coverage import env
from coverage.context import qualname_from_frame
@@ -279,9 +281,8 @@ class QualnameTest(CoverageTest):
c.meth = patch_meth
assert c.meth(c) == "tests.test_context.patch_meth"
+ @pytest.mark.skipif(not env.PY2, reason="Old-style classes are only in Python 2")
def test_oldstyle(self):
- if not env.PY2:
- self.skipTest("Old-style classes are only in Python 2")
assert OldStyle().meth() == "tests.test_context.OldStyle.meth"
assert OldChild().meth() == "tests.test_context.OldStyle.meth"
diff --git a/tests/test_coverage.py b/tests/test_coverage.py
index 52b405e8..00648c18 100644
--- a/tests/test_coverage.py
+++ b/tests/test_coverage.py
@@ -343,10 +343,8 @@ class SimpleStatementTest(CoverageTest):
""",
[1,2,3,6,9], "")
+ @pytest.mark.skipif(env.PY3, reason="No more print statement in Python 3.")
def test_print(self):
- if env.PY3: # Print statement is gone in Py3k.
- self.skipTest("No more print statement in Python 3.")
-
self.check_coverage("""\
print "hello, world!"
print ("hey: %d" %
@@ -486,12 +484,11 @@ class SimpleStatementTest(CoverageTest):
""",
lines=lines, missing=missing)
+ @pytest.mark.skipif(env.PY2, reason="Expected failure: peephole optimization of jumps to jumps")
def test_strange_unexecuted_continue(self):
# Peephole optimization of jumps to jumps can mean that some statements
# never hit the line tracer. The behavior is different in different
# versions of Python, so be careful when running this test.
- if env.PY2:
- self.skipTest("Expected failure: peephole optimization of jumps to jumps")
self.check_coverage("""\
a = b = c = 0
for n in range(100):
diff --git a/tests/test_execfile.py b/tests/test_execfile.py
index d221f2d3..3cdd1ed9 100644
--- a/tests/test_execfile.py
+++ b/tests/test_execfile.py
@@ -110,7 +110,7 @@ class RunPycFileTest(CoverageTest):
def make_pyc(self): # pylint: disable=inconsistent-return-statements
"""Create a .pyc file, and return the path to it."""
if env.JYTHON:
- self.skipTest("Can't make .pyc files on Jython")
+ pytest.skip("Can't make .pyc files on Jython")
self.make_file("compiled.py", """\
def doit():
diff --git a/tests/test_files.py b/tests/test_files.py
index 6a9556ec..6040b889 100644
--- a/tests/test_files.py
+++ b/tests/test_files.py
@@ -396,15 +396,11 @@ class FindPythonFilesTest(CoverageTest):
])
+@pytest.mark.skipif(not env.WINDOWS, reason="Only need to run Windows tests on Windows.")
class WindowsFileTest(CoverageTest):
"""Windows-specific tests of file name handling."""
run_in_temp_dir = False
- def setUp(self):
- if not env.WINDOWS:
- self.skipTest("Only need to run Windows tests on Windows.")
- super(WindowsFileTest, self).setUp()
-
def test_actual_path(self):
assert actual_path(r'c:\Windows') == actual_path(r'C:\wINDOWS')
diff --git a/tests/test_oddball.py b/tests/test_oddball.py
index f4565607..b7307887 100644
--- a/tests/test_oddball.py
+++ b/tests/test_oddball.py
@@ -145,10 +145,8 @@ class MemoryLeakTest(CoverageTest):
"""
@flaky
+ @pytest.mark.skipif(env.JYTHON, reason="Don't bother on Jython")
def test_for_leaks(self):
- if env.JYTHON:
- self.skipTest("Don't bother on Jython")
-
# Our original bad memory leak only happened on line numbers > 255, so
# make a code object with more lines than that. Ugly string mumbo
# jumbo to get 300 blank lines at the beginning..
@@ -194,11 +192,10 @@ class MemoryLeakTest(CoverageTest):
class MemoryFumblingTest(CoverageTest):
"""Test that we properly manage the None refcount."""
+ @pytest.mark.skipif(not env.C_TRACER, reason="Only the C tracer has refcounting issues")
def test_dropping_none(self): # pragma: not covered
- if not env.C_TRACER:
- self.skipTest("Only the C tracer has refcounting issues")
# TODO: Mark this so it will only be run sometimes.
- self.skipTest("This is too expensive for now (30s)")
+ pytest.skip("This is too expensive for now (30s)")
# Start and stop coverage thousands of times to flush out bad
# reference counting, maybe.
self.make_file("the_code.py", """\
@@ -227,13 +224,11 @@ class MemoryFumblingTest(CoverageTest):
assert "Fatal" not in out
+@pytest.mark.skipif(env.JYTHON, reason="Pyexpat isn't a problem on Jython")
class PyexpatTest(CoverageTest):
"""Pyexpat screws up tracing. Make sure we've counter-defended properly."""
def test_pyexpat(self):
- if env.JYTHON:
- self.skipTest("Pyexpat isn't a problem on Jython")
-
# pyexpat calls the trace function explicitly (inexplicably), and does
# it wrong for exceptions. Parsing a DOCTYPE for some reason throws
# an exception internally, and triggers its wrong behavior. This test
@@ -555,10 +550,9 @@ class ExecTest(CoverageTest):
assert statements == [31]
assert missing == []
+ @pytest.mark.skipif(env.PY2, reason="Python 2 can't seem to compile the file.")
def test_unencodable_filename(self):
# https://github.com/nedbat/coveragepy/issues/891
- if env.PYVERSION < (3, 0):
- self.skipTest("Python 2 can't seem to compile the file.")
self.make_file("bug891.py", r"""exec(compile("pass", "\udcff.py", "exec"))""")
cov = coverage.Coverage()
self.start_import_stop(cov, "bug891")
diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py
index c7375cb5..86b1fdbe 100644
--- a/tests/test_phystokens.py
+++ b/tests/test_phystokens.py
@@ -132,11 +132,9 @@ class SourceEncodingTest(CoverageTest):
for _, source, expected in ENCODING_DECLARATION_SOURCES:
assert source_encoding(source) == expected, "Wrong encoding in %r" % source
+ # PyPy3 gets this case wrong. Not sure what I can do about it, so skip the test.
+ @pytest.mark.skipif(env.PYPY3, reason="PyPy3 is wrong about non-comment encoding. Skip it.")
def test_detect_source_encoding_not_in_comment(self):
- if env.PYPY3: # pragma: no metacov
- # PyPy3 gets this case wrong. Not sure what I can do about it,
- # so skip the test.
- self.skipTest("PyPy3 is wrong about non-comment encoding. Skip it.")
# Should not detect anything here
source = b'def parse(src, encoding=None):\n pass'
assert source_encoding(source) == DEF_ENCODING
diff --git a/tests/test_plugins.py b/tests/test_plugins.py
index f53de4fb..aeffdb80 100644
--- a/tests/test_plugins.py
+++ b/tests/test_plugins.py
@@ -256,12 +256,10 @@ class PluginTest(CoverageTest):
assert out == ""
+@pytest.mark.skipif(env.C_TRACER, reason="This test is only about PyTracer.")
class PluginWarningOnPyTracer(CoverageTest):
"""Test that we get a controlled exception with plugins on PyTracer."""
def test_exception_if_plugins_on_pytracer(self):
- if env.C_TRACER:
- self.skipTest("This test is only about PyTracer.")
-
self.make_file("simple.py", "a = 1")
cov = coverage.Coverage()
@@ -274,14 +272,10 @@ class PluginWarningOnPyTracer(CoverageTest):
self.start_import_stop(cov, "simple")
+@pytest.mark.skipif(not env.C_TRACER, reason="Plugins are only supported with the C tracer.")
class FileTracerTest(CoverageTest):
"""Tests of plugins that implement file_tracer."""
- def setUp(self):
- if not env.C_TRACER:
- self.skipTest("Plugins are only supported with the C tracer.")
- super(FileTracerTest, self).setUp()
-
class GoodFileTracerTest(FileTracerTest):
"""Tests of file tracer plugin happy paths."""
diff --git a/tests/test_process.py b/tests/test_process.py
index 04a6ecde..01fd1eb8 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -533,10 +533,8 @@ class ProcessTest(CoverageTest):
assert status == status2
assert status == 0
+ @pytest.mark.skipif(not hasattr(os, "fork"), reason="Can't test os.fork, it doesn't exist.")
def test_fork(self):
- if not hasattr(os, 'fork'):
- self.skipTest("Can't test os.fork since it doesn't exist.")
-
self.make_file("fork.py", """\
import os
@@ -735,13 +733,9 @@ class ProcessTest(CoverageTest):
@pytest.mark.expensive
@pytest.mark.skipif(env.METACOV, reason="Can't test fullcoverage when measuring ourselves")
+ @pytest.mark.skipif(env.PY2, reason="fullcoverage doesn't work on Python 2.")
+ @pytest.mark.skipif(not env.C_TRACER, reason="fullcoverage only works with the C tracer.")
def test_fullcoverage(self):
- if env.PY2: # This doesn't work on Python 2.
- self.skipTest("fullcoverage doesn't work on Python 2.")
- # It only works with the C tracer.
- if not env.C_TRACER:
- self.skipTest("fullcoverage only works with the C tracer.")
-
# fullcoverage is a trick to get stdlib modules measured from
# the very beginning of the process. Here we import os and
# then check how many lines are measured.
@@ -768,10 +762,9 @@ class ProcessTest(CoverageTest):
env.PYPY3 and (env.PYPYVERSION >= (7, 1, 1)),
"https://bitbucket.org/pypy/pypy/issues/3074"
)
+ # Jython as of 2.7.1rc3 won't compile a filename that isn't utf8.
+ @pytest.mark.skipif(env.JYTHON, reason="Jython can't handle this test")
def test_lang_c(self):
- if env.JYTHON:
- # Jython as of 2.7.1rc3 won't compile a filename that isn't utf8.
- self.skipTest("Jython can't handle this test")
# LANG=C forces getfilesystemencoding on Linux to 'ascii', which causes
# failures with non-ascii file names. We don't want to make a real file
# with strange characters, though, because that gets the test runners
@@ -881,9 +874,10 @@ class EnvironmentTest(CoverageTest):
actual = self.run_command("coverage run -m process_test.try_execfile")
self.assert_tryexecfile_output(expected, actual)
+ @pytest.mark.skipif(env.PYVERSION == (3, 5, 4, 'final', 0, 0),
+ reason="3.5.4 broke this: https://bugs.python.org/issue32551"
+ )
def test_coverage_run_dir_is_like_python_dir(self):
- if env.PYVERSION == (3, 5, 4, 'final', 0, 0): # pragma: obscure
- self.skipTest("3.5.4 broke this: https://bugs.python.org/issue32551")
with open(TRY_EXECFILE) as f:
self.make_file("with_main/__main__.py", f.read())
@@ -911,9 +905,10 @@ class EnvironmentTest(CoverageTest):
else:
self.assert_tryexecfile_output(expected, actual)
+ @pytest.mark.skipif(env.PY2,
+ reason="Python 2 runs __main__ twice, I can't be bothered to make it work."
+ )
def test_coverage_run_dashm_dir_with_init_is_like_python(self):
- if env.PY2:
- self.skipTest("Python 2 runs __main__ twice, I can't be bothered to make it work.")
with open(TRY_EXECFILE) as f:
self.make_file("with_main/__main__.py", f.read())
self.make_file("with_main/__init__.py", "")
@@ -1040,9 +1035,8 @@ class EnvironmentTest(CoverageTest):
out = self.run_command("python -m run_coverage run how_is_it.py")
assert "hello-xyzzy" in out
+ @pytest.mark.skipif(env.WINDOWS, reason="Windows can't make symlinks")
def test_bug_862(self):
- if env.WINDOWS:
- self.skipTest("Windows can't make symlinks")
# This simulates how pyenv and pyenv-virtualenv end up creating the
# coverage executable.
self.make_file("elsewhere/bin/fake-coverage", """\
@@ -1118,9 +1112,10 @@ class ExcepthookTest(CoverageTest):
data.read()
assert line_counts(data)['excepthook.py'] == 7
+ @pytest.mark.skipif(not env.CPYTHON,
+ reason="non-CPython handles excepthook exits differently, punt for now."
+ )
def test_excepthook_exit(self):
- if not env.CPYTHON:
- self.skipTest("non-CPython handles excepthook exits differently, punt for now.")
self.make_file("excepthook_exit.py", """\
import sys
@@ -1140,9 +1135,8 @@ class ExcepthookTest(CoverageTest):
assert "in excepthook" in py_out
assert cov_out == py_out
+ @pytest.mark.skipif(env.PYPY, reason="PyPy handles excepthook throws differently.")
def test_excepthook_throw(self):
- if env.PYPY:
- self.skipTest("PyPy handles excepthook throws differently, punt for now.")
self.make_file("excepthook_throw.py", """\
import sys
@@ -1167,16 +1161,12 @@ class ExcepthookTest(CoverageTest):
assert cov_out == py_out
+@pytest.mark.skipif(env.JYTHON, reason="Coverage command names don't work on Jython")
class AliasedCommandTest(CoverageTest):
"""Tests of the version-specific command aliases."""
run_in_temp_dir = False
- def setUp(self):
- if env.JYTHON:
- self.skipTest("Coverage command names don't work on Jython")
- super(AliasedCommandTest, self).setUp()
-
def test_major_version_works(self):
# "coverage2" works on py2
cmd = "coverage%d" % sys.version_info[0]
@@ -1289,14 +1279,10 @@ class FailUnderEmptyFilesTest(CoverageTest):
assert st == 2
+@pytest.mark.skipif(env.JYTHON, reason="Jython doesn't like accented file names")
class UnicodeFilePathsTest(CoverageTest):
"""Tests of using non-ascii characters in the names of files."""
- def setUp(self):
- if env.JYTHON:
- self.skipTest("Jython doesn't like accented file names")
- super(UnicodeFilePathsTest, self).setUp()
-
def test_accented_dot_py(self):
# Make a file with a non-ascii character in the filename.
self.make_file(u"h\xe2t.py", "print('accented')")
@@ -1380,14 +1366,10 @@ class UnicodeFilePathsTest(CoverageTest):
assert out == report_expected
+@pytest.mark.skipif(env.WINDOWS, reason="Windows can't delete the directory in use.")
class YankedDirectoryTest(CoverageTest):
"""Tests of what happens when the current directory is deleted."""
- def setUp(self):
- if env.WINDOWS:
- self.skipTest("Windows can't delete the directory in use.")
- super(YankedDirectoryTest, self).setUp()
-
BUG_806 = """\
import os
import sys
diff --git a/tests/test_summary.py b/tests/test_summary.py
index e3694000..0632c8f5 100644
--- a/tests/test_summary.py
+++ b/tests/test_summary.py
@@ -564,10 +564,8 @@ class SummaryTest(UsingModulesMixin, CoverageTest):
errmsg = re.sub(r": '.*' at", ": 'error' at", errmsg)
assert errmsg == "Couldn't parse 'mycode.py' as Python source: 'error' at line 1"
+ @pytest.mark.skipif(env.JYTHON, reason="Jython doesn't like accented file names")
def test_accenteddotpy_not_python(self):
- if env.JYTHON:
- self.skipTest("Jython doesn't like accented file names")
-
# We run a .py file with a non-ascii name, and when reporting, we can't
# parse it as Python. We should get an error message in the report.
@@ -709,10 +707,8 @@ class SummaryTest(UsingModulesMixin, CoverageTest):
assert "TheCode" in report
assert "thecode" not in report
+ @pytest.mark.skipif(not env.WINDOWS, reason=".pyw files are only on Windows.")
def test_pyw_files(self):
- if not env.WINDOWS:
- self.skipTest(".pyw files are only on Windows.")
-
# https://github.com/nedbat/coveragepy/issues/261
self.make_file("start.pyw", """\
import mod
@@ -749,11 +745,8 @@ class SummaryTest(UsingModulesMixin, CoverageTest):
report = self.get_report(cov).splitlines()
assert "mod.py 1 0 100%" in report
+ @pytest.mark.skipif(env.PYPY2, reason="PyPy2 doesn't run bare .pyc files")
def test_missing_py_file_during_run(self):
- # PyPy2 doesn't run bare .pyc files.
- if env.PYPY2:
- self.skipTest("PyPy2 doesn't run bare .pyc files")
-
# Create two Python files.
self.make_file("mod.py", "a = 1\n")
self.make_file("main.py", "import mod\n")