summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-03-08 19:19:49 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-03-11 06:38:43 -0500
commit7cf60e32077ae480ebd9b435c6c0dc3c0042b30f (patch)
treedfb8f238496963895c3c4eaf1fb586c00540eccf
parentb69daacebf81149e87642324e13ad068853cea93 (diff)
downloadpython-coveragepy-git-7cf60e32077ae480ebd9b435c6c0dc3c0042b30f.tar.gz
refactor: use pytest.skip instead of unittest's
-rw-r--r--tests/mixins.py7
-rw-r--r--tests/test_testing.py12
2 files changed, 12 insertions, 7 deletions
diff --git a/tests/mixins.py b/tests/mixins.py
index 8fe0690b..4954a6a5 100644
--- a/tests/mixins.py
+++ b/tests/mixins.py
@@ -13,7 +13,6 @@ import os.path
import sys
import types
import textwrap
-import unittest
import pytest
@@ -148,19 +147,19 @@ class TempDirMixin(object):
def convert_skip_exceptions(method):
- """A decorator for test methods to convert StopEverything to SkipTest."""
+ """A decorator for test methods to convert StopEverything to skips."""
@functools.wraps(method)
def _wrapper(*args, **kwargs):
try:
result = method(*args, **kwargs)
except StopEverything:
- raise unittest.SkipTest("StopEverything!")
+ pytest.skip("StopEverything!")
return result
return _wrapper
class SkipConvertingMetaclass(type):
- """Decorate all test methods to convert StopEverything to SkipTest."""
+ """Decorate all test methods to convert StopEverything to skips."""
def __new__(cls, name, bases, attrs):
for attr_name, attr_value in attrs.items():
if attr_name.startswith('test_') and isinstance(attr_value, types.FunctionType):
diff --git a/tests/test_testing.py b/tests/test_testing.py
index 1e30fa2f..e3053e96 100644
--- a/tests/test_testing.py
+++ b/tests/test_testing.py
@@ -8,7 +8,6 @@ import datetime
import os
import re
import sys
-import unittest
import pytest
@@ -317,6 +316,13 @@ def test_re_line_bad(text, pat):
def test_convert_skip_exceptions():
+ # pytest doesn't expose the exception raised by pytest.skip, so let's
+ # make one to get the class.
+ try:
+ pytest.skip("Just to get the exception")
+ except BaseException as exc:
+ pytest_Skipped = type(exc)
+
@convert_skip_exceptions
def some_method(ret=None, exc=None):
"""Be like a test case."""
@@ -331,8 +337,8 @@ def test_convert_skip_exceptions():
with pytest.raises(ValueError):
some_method(exc=ValueError)
- # But a StopEverything becomes a SkipTest.
- with pytest.raises(unittest.SkipTest):
+ # But a StopEverything becomes a skip.
+ with pytest.raises(pytest_Skipped):
some_method(exc=StopEverything)