Call Python 3.8 doClassCleanups (#8033)
This commit is contained in:
committed by
GitHub
parent
b7ba76653d
commit
eda681af2b
@@ -1260,3 +1260,163 @@ def test_plain_unittest_does_not_support_async(testdir):
|
||||
"*1 passed*",
|
||||
]
|
||||
result.stdout.fnmatch_lines(expected_lines)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 8), reason="Feature introduced in Python 3.8"
|
||||
)
|
||||
def test_do_class_cleanups_on_success(testdir):
|
||||
testpath = testdir.makepyfile(
|
||||
"""
|
||||
import unittest
|
||||
class MyTestCase(unittest.TestCase):
|
||||
values = []
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
def cleanup():
|
||||
cls.values.append(1)
|
||||
cls.addClassCleanup(cleanup)
|
||||
def test_one(self):
|
||||
pass
|
||||
def test_two(self):
|
||||
pass
|
||||
def test_cleanup_called_exactly_once():
|
||||
assert MyTestCase.values == [1]
|
||||
"""
|
||||
)
|
||||
reprec = testdir.inline_run(testpath)
|
||||
passed, skipped, failed = reprec.countoutcomes()
|
||||
assert failed == 0
|
||||
assert passed == 3
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 8), reason="Feature introduced in Python 3.8"
|
||||
)
|
||||
def test_do_class_cleanups_on_setupclass_failure(testdir):
|
||||
testpath = testdir.makepyfile(
|
||||
"""
|
||||
import unittest
|
||||
class MyTestCase(unittest.TestCase):
|
||||
values = []
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
def cleanup():
|
||||
cls.values.append(1)
|
||||
cls.addClassCleanup(cleanup)
|
||||
assert False
|
||||
def test_one(self):
|
||||
pass
|
||||
def test_cleanup_called_exactly_once():
|
||||
assert MyTestCase.values == [1]
|
||||
"""
|
||||
)
|
||||
reprec = testdir.inline_run(testpath)
|
||||
passed, skipped, failed = reprec.countoutcomes()
|
||||
assert failed == 1
|
||||
assert passed == 1
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 8), reason="Feature introduced in Python 3.8"
|
||||
)
|
||||
def test_do_class_cleanups_on_teardownclass_failure(testdir):
|
||||
testpath = testdir.makepyfile(
|
||||
"""
|
||||
import unittest
|
||||
class MyTestCase(unittest.TestCase):
|
||||
values = []
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
def cleanup():
|
||||
cls.values.append(1)
|
||||
cls.addClassCleanup(cleanup)
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
assert False
|
||||
def test_one(self):
|
||||
pass
|
||||
def test_two(self):
|
||||
pass
|
||||
def test_cleanup_called_exactly_once():
|
||||
assert MyTestCase.values == [1]
|
||||
"""
|
||||
)
|
||||
reprec = testdir.inline_run(testpath)
|
||||
passed, skipped, failed = reprec.countoutcomes()
|
||||
assert passed == 3
|
||||
|
||||
|
||||
def test_do_cleanups_on_success(testdir):
|
||||
testpath = testdir.makepyfile(
|
||||
"""
|
||||
import unittest
|
||||
class MyTestCase(unittest.TestCase):
|
||||
values = []
|
||||
def setUp(self):
|
||||
def cleanup():
|
||||
self.values.append(1)
|
||||
self.addCleanup(cleanup)
|
||||
def test_one(self):
|
||||
pass
|
||||
def test_two(self):
|
||||
pass
|
||||
def test_cleanup_called_the_right_number_of_times():
|
||||
assert MyTestCase.values == [1, 1]
|
||||
"""
|
||||
)
|
||||
reprec = testdir.inline_run(testpath)
|
||||
passed, skipped, failed = reprec.countoutcomes()
|
||||
assert failed == 0
|
||||
assert passed == 3
|
||||
|
||||
|
||||
def test_do_cleanups_on_setup_failure(testdir):
|
||||
testpath = testdir.makepyfile(
|
||||
"""
|
||||
import unittest
|
||||
class MyTestCase(unittest.TestCase):
|
||||
values = []
|
||||
def setUp(self):
|
||||
def cleanup():
|
||||
self.values.append(1)
|
||||
self.addCleanup(cleanup)
|
||||
assert False
|
||||
def test_one(self):
|
||||
pass
|
||||
def test_two(self):
|
||||
pass
|
||||
def test_cleanup_called_the_right_number_of_times():
|
||||
assert MyTestCase.values == [1, 1]
|
||||
"""
|
||||
)
|
||||
reprec = testdir.inline_run(testpath)
|
||||
passed, skipped, failed = reprec.countoutcomes()
|
||||
assert failed == 2
|
||||
assert passed == 1
|
||||
|
||||
|
||||
def test_do_cleanups_on_teardown_failure(testdir):
|
||||
testpath = testdir.makepyfile(
|
||||
"""
|
||||
import unittest
|
||||
class MyTestCase(unittest.TestCase):
|
||||
values = []
|
||||
def setUp(self):
|
||||
def cleanup():
|
||||
self.values.append(1)
|
||||
self.addCleanup(cleanup)
|
||||
def tearDown(self):
|
||||
assert False
|
||||
def test_one(self):
|
||||
pass
|
||||
def test_two(self):
|
||||
pass
|
||||
def test_cleanup_called_the_right_number_of_times():
|
||||
assert MyTestCase.values == [1, 1]
|
||||
"""
|
||||
)
|
||||
reprec = testdir.inline_run(testpath)
|
||||
passed, skipped, failed = reprec.countoutcomes()
|
||||
assert failed == 2
|
||||
assert passed == 1
|
||||
|
||||
Reference in New Issue
Block a user