diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2021-09-19 19:36:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-19 19:36:03 (GMT) |
commit | bedce3538cca3469ac3efc614ef062367cbb2ff1 (patch) | |
tree | 4eeab0425eddc0520a29f6ebaadb9d8171523394 /Lib/test/test_gc.py | |
parent | 9c23a1ebade19f20c7d6e592a7d0329545a9a746 (diff) | |
download | cpython-bedce3538cca3469ac3efc614ef062367cbb2ff1.zip cpython-bedce3538cca3469ac3efc614ef062367cbb2ff1.tar.gz cpython-bedce3538cca3469ac3efc614ef062367cbb2ff1.tar.bz2 |
[3.10] bpo-45229: Remove test_main in many tests (GH-28405) (GH-28455)
Instead of explicitly enumerate test classes for run_unittest()
use the unittest ability to discover tests. This also makes these
tests discoverable and runnable with unittest.
load_tests() can be used for dynamic generating tests and adding
doctests. setUpModule(), tearDownModule() and addModuleCleanup()
can be used for running code before and after all module tests.
(cherry picked from commit 40348acc180580371d25f75f46b27048e35f2435)
Diffstat (limited to 'Lib/test/test_gc.py')
-rw-r--r-- | Lib/test/test_gc.py | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index 1528cf6..6c28b2b 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -1,6 +1,6 @@ import unittest import unittest.mock -from test.support import (verbose, refcount_test, run_unittest, +from test.support import (verbose, refcount_test, cpython_only) from test.support.import_helper import import_module from test.support.os_helper import temp_dir, TESTFN, unlink @@ -1389,30 +1389,27 @@ class PythonFinalizationTests(unittest.TestCase): assert_python_ok("-c", code) -def test_main(): +def setUpModule(): + global enabled, debug enabled = gc.isenabled() gc.disable() assert not gc.isenabled() debug = gc.get_debug() gc.set_debug(debug & ~gc.DEBUG_LEAK) # this test is supposed to leak + gc.collect() # Delete 2nd generation garbage + + +def tearDownModule(): + gc.set_debug(debug) + # test gc.enable() even if GC is disabled by default + if verbose: + print("restoring automatic collection") + # make sure to always test gc.enable() + gc.enable() + assert gc.isenabled() + if not enabled: + gc.disable() - try: - gc.collect() # Delete 2nd generation garbage - run_unittest( - GCTests, - GCCallbackTests, - GCTogglingTests, - PythonFinalizationTests) - finally: - gc.set_debug(debug) - # test gc.enable() even if GC is disabled by default - if verbose: - print("restoring automatic collection") - # make sure to always test gc.enable() - gc.enable() - assert gc.isenabled() - if not enabled: - gc.disable() if __name__ == "__main__": - test_main() + unittest.main() |