summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/case.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-99645: Fix a bug in handling class cleanups in unittest.TestCase (GH-99646)Serhiy Storchaka2022-11-221-5/+5
| | | | | Now addClassCleanup() uses separate lists for different TestCase subclasses, and doClassCleanups() only cleans up the particular class.
* gh-97837: Change deprecation warning message in `unittest` (#97838)Nikita Sobolev2022-10-051-1/+1
|
* Revert "bpo-45162: Revert "Remove many old deprecated unittest features"" ↵Serhiy Storchaka2022-06-261-50/+0
| | | | | | (GH-92556) This reverts commit b50322d20337ca468f2070eedb051a16ee1eba94.
* bpo-45046: Support context managers in unittest (GH-28045)Serhiy Storchaka2022-05-081-0/+32
| | | | | | Add methods enterContext() and enterClassContext() in TestCase. Add method enterAsyncContext() in IsolatedAsyncioTestCase. Add function enterModuleContext().
* bpo-14265: Adds fully qualified test name to unittest output (GH-32138)Sam Ezeh2022-03-291-1/+1
| | | Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
* bpo-45162: Revert "Remove many old deprecated unittest features" (GH-30935)Gregory P. Smith2022-01-271-0/+50
| | | | | | | | | | Revert "bpo-45162: Remove many old deprecated unittest features (GH-28268)" This reverts commit b0a6ede3d0bd6fa4ffe413ab4dfc1059201df25b. We're deferring this change until 3.12 while upstream projects that use the legacy assertion method names are fixed. See the issue for links to the discussion. Many upstream projects now have issues and PRs filed.
* bpo-45238: Fix unittest.IsolatedAsyncioTestCase.debug() (GH-28449)Serhiy Storchaka2021-09-221-5/+5
| | | | | | It runs now asynchronous methods and callbacks. If it fails, doCleanups() can be called for cleaning up.
* bpo-30856: Update TestResult early, without buffering in _Outcome (GH-28180)Serhiy Storchaka2021-09-191-36/+30
| | | | | | | TestResult methods addFailure(), addError(), addSkip() and addSubTest() are now called immediately after raising an exception in test or finishing a subtest. Previously they were called only after finishing the test clean up.
* bpo-36674: Honour the skipping decorators in TestCase.debug() (GH-28446)Serhiy Storchaka2021-09-181-1/+9
| | | | | | | | unittest.TestCase.debug() raises now a SkipTest if the class or the test method are decorated with the skipping decorator. Previously it only raised a SkipTest if the test method was decorated with other decorator in addition to the skipping decorator, or if SkipTest was explicitly raised in the test or setup methods.
* bpo-45162: Remove many old deprecated unittest features (GH-28268)Serhiy Storchaka2021-09-171-50/+0
| | | | | | | * "fail*" and "assert*" aliases of TestCase methods. * Broken from start TestCase method assertDictContainsSubset(). * Ignored TestLoader.loadTestsFromModule() parameter use_load_tests. * Old alias _TextTestResult of TextTestResult.
* bpo-41620: TestCase.run() now always return a TestResult instance (GH-28030)Serhiy Storchaka2021-08-301-1/+1
| | | | | | Previously it returned None if the test class or method was decorated with a skipping decorator. Co-authored-by: Iman Tabrizian <iman.tabrizian@gmail.com>
* bpo-41322: Add unit tests for deprecation of test return values (GH-27846)andrei kulakov2021-08-221-1/+1
| | | | Also fix the traceback of warnings.
* bpo-44955: Always call stopTestRun() for implicitly created TestResult ↵Serhiy Storchaka2021-08-221-52/+50
| | | | | | | | objects (GH-27831) Method stopTestRun() is now always called in pair with method startTestRun() for TestResult objects implicitly created in TestCase.run(). Previously it was not called for test methods and classes decorated with a skipping decorator.
* bpo-41322: added deprecation warning for tests returning value!=None (GH-27748)andrei kulakov2021-08-191-1/+3
|
* bpo-39385: Add an assertNoLogs context manager to unittest.TestCase (GH-18067)Kit Choi2020-07-011-2/+10
| | | Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
* bpo-29620: iterate over a copy of sys.modules (GH-4800)kernc2020-06-111-1/+1
| | | | | | | unittest.TestCase.assertWarns no longer raises a RuntimeException when accessing a module's ``__warningregistry__`` causes importation of a new module, or when a new module is imported in another thread. Patch by Kernc.
* bpo-40275: Avoid importing logging in test.support (GH-19601)Serhiy Storchaka2020-04-251-68/+2
| | | | | Import logging lazily in assertLogs() in unittest. Move TestHandler from test.support to logging_helper.
* bpo-39481: PEP 585 for a variety of modules (GH-19423)Batuhan Taşkaya2020-04-101-0/+2
| | | | | | | | | | - concurrent.futures - ctypes - http.cookies - multiprocessing - queue - tempfile - unittest.case - urllib.parse
* bpo-39450 Stripped whitespace before parsing the docstring in ↵Steve Cirelli2020-02-031-1/+1
| | | | TestCase.shortDescription (GH-18175)
* Remove binding of captured exceptions when not used to reduce the chances of ↵Pablo Galindo2019-11-191-1/+1
| | | | | | | creating cycles (GH-17246) Capturing exceptions into names can lead to reference cycles though the __traceback__ attribute of the exceptions in some obscure cases that have been reported previously and fixed individually. As these variables are not used anyway, we can remove the binding to reduce the chances of creating reference cycles. See for example GH-13135
* bpo-34596: Fallback to a default reason when @unittest.skip is uncalled (#9082)Naitree Zhu2019-09-091-0/+5
| | | | | | | | * bpo-34596: Fallback to a default reason when @unittest.skip is uncalled * Change default reason to empty string * Fix rst formatting of NEWS entry
* [3.9] bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-12620)Serhiy Storchaka2019-06-051-18/+1
| | | Turn deprecation warnings added in 3.8 into TypeError.
* bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-13700)Serhiy Storchaka2019-06-011-27/+3
|
* bpo-32972: Async test case (GH-13386)Andrew Svetlov2019-05-291-4/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add explicit `asyncSetUp` and `asyncTearDown` methods. The rest is the same as for #13228 `AsyncTestCase` create a loop instance for every test for the sake of test isolation. Sometimes a loop shared between all tests can speed up tests execution time a lot but it requires control of closed resources after every test finish. Basically, it requires nested supervisors support that was discussed with @1st1 many times. Sorry, asyncio supervisors have no chance to land on Python 3.8. The PR intentionally does not provide API for changing the used event loop or getting the test loop: use `asyncio.set_event_loop_policy()` and `asyncio.get_event_loop()` instead. The PR adds four overridable methods to base `unittest.TestCase` class: ``` def _callSetUp(self): self.setUp() def _callTestMethod(self, method): method() def _callTearDown(self): self.tearDown() def _callCleanup(self, function, /, *args, **kwargs): function(*args, **kwargs) ``` It allows using asyncio facilities with minimal influence on the unittest code. The last but not least: the PR respects contextvars. The context variable installed by `asyncSetUp` is available on test, `tearDown` and a coroutine scheduled by `addCleanup`. https://bugs.python.org/issue32972
* bpo-36542: Allow to overwrite the signature for Python functions. (GH-12705)Serhiy Storchaka2019-05-061-1/+4
|
* Document that TestCase.assertCountEqual() can take iterables (GH-686)jkleint2019-04-231-3/+2
|
* bpo-36492: Deprecate passing some arguments as keyword arguments. (GH-12637)Serhiy Storchaka2019-04-011-3/+41
| | | | | | | | | | | | | | | | | | | | | | Deprecated passing the following arguments as keyword arguments: - "func" in functools.partialmethod(), weakref.finalize(), profile.Profile.runcall(), cProfile.Profile.runcall(), bdb.Bdb.runcall(), trace.Trace.runfunc() and curses.wrapper(). - "function" in unittest.addModuleCleanup() and unittest.TestCase.addCleanup(). - "fn" in the submit() method of concurrent.futures.ThreadPoolExecutor and concurrent.futures.ProcessPoolExecutor. - "callback" in contextlib.ExitStack.callback(), contextlib.AsyncExitStack.callback() and contextlib.AsyncExitStack.push_async_callback(). - "c" and "typeid" in the create() method of multiprocessing.managers.Server and multiprocessing.managers.SharedMemoryServer. - "obj" in weakref.finalize(). Also allowed to pass arbitrary keyword arguments (even "self" and "func") if the above arguments are passed as positional argument.
* bpo-24412: Adds cleanUps for setUpClass and setUpModule. (GH-9190)Lisa Roach2018-11-091-1/+45
|
* bpo-34900: Make TestCase.debug() work with subtests (GH-9707)Bruno Oliveira2018-10-121-1/+1
|
* bpo-34318: Convert deprecation warnings to errors in assertRaises() etc. ↵Serhiy Storchaka2018-08-191-7/+2
| | | | (GH-8623)
* Update TestCase.assertAlmostEqual and assertNotAlmostEqual docstrings. (GH-3998)Ron2017-10-181-2/+3
| | | | The word "difference" from missing the sentence. This clarifies that it compares the difference between the two objects.
* bpo-30397: Add re.Pattern and re.Match. (#1646)Serhiy Storchaka2017-10-041-2/+2
|
* bpo-30664: The description of a unittest subtest now preserves the (#2265)Serhiy Storchaka2017-06-231-2/+12
| | | | order of keyword arguments of TestCase.subTest().
* bpo-30190: improved error msg for assertAlmostEqual(delta=...) (#1331)Giampaolo Rodola2017-05-011-14/+21
| | | | | | | | | | | | * #30190 / unittest / assertAlmostEqual(delta=...) / error msg: show the difference between the 2 numbers in case of failure * safe_repr() diff * also show difference when passing 'places' argument * refactoring * update Misc/NEWS
* Fix ref cycles in TestCase.assertRaises() (#193)Victor Stinner2017-03-271-22/+30
| | | | bpo-23890: unittest.TestCase.assertRaises() now manually breaks a reference cycle to not keep objects alive longer than expected.
* Issue #25651: Allow falsy values to be used for msg parameter of subTest()Berker Peksag2016-09-211-2/+3
|
* Issue #27626: Spelling fixes in docs, comments and internal namesMartin Panter2016-07-281-2/+2
| | | | Based on patch by Ville Skyttä.
* Issue #26837: assertSequenceEqual() now correctly outputs non-stringifiedSerhiy Storchaka2016-04-251-3/+3
| | | | | differing items (like bytes in the -b mode). This affects assertListEqual() and assertTupleEqual().
* Issue #21112: Fix regression in unittest.expectedFailure on subclasses.Robert Collins2015-08-271-2/+5
|\ | | | | | | Patch from Berker Peksag.
| * Issue #21112: Fix regression in unittest.expectedFailure on subclasses.Robert Collins2015-08-271-2/+5
| | | | | | | | Patch from Berker Peksag.
| * Reverted issue #24134 changes (except new tests).Serhiy Storchaka2015-05-161-13/+11
| |
* | Issue #20362: Honour TestCase.longMessage correctly in assertRegex.Robert Collins2015-08-191-7/+11
| | | | | | | | Patch from Ilia Kurenkov.
* | Issue #15836: assertRaises(), assertRaisesRegex(), assertWarns() andSerhiy Storchaka2015-05-211-0/+13
| | | | | | | | | | assertWarnsRegex() assertments now check the type of the first argument to prevent possible user error. Based on patch by Daniel Wagner-Hall.
* | Issue #24134: assertRaises(), assertRaisesRegex(), assertWarns() andSerhiy Storchaka2015-05-161-44/+44
|/ | | | | assertWarnsRegex() checks now emits a deprecation warning when callable is None or keyword arguments except msg is passed in the context manager mode.
* Fixed English in error message.Serhiy Storchaka2015-05-061-1/+1
|
* Issue #24134: assertRaises(), assertRaisesRegex(), assertWarns() andSerhiy Storchaka2015-05-061-11/+13
| | | | | | assertWarnsRegex() checks are not longer successful if the callable is None. Added tests for assertRaises().
* Issue #21408: The default __ne__() now returns NotImplemented if __eq__()Serhiy Storchaka2015-01-261-3/+0
| | | | returned NotImplemented. Removed incorrect implementations of __ne__().
* Issue #9815: assertRaises now tries to clear references to local variables ↵Antoine Pitrou2014-04-281-0/+3
| | | | in the exception's traceback.
* backport: #20145: assert[Raises|Warns]Regex now raise TypeError on bad regex.R David Murray2014-03-251-1/+1
| | | | | | | Previously a non-string, non-regex second argument and missing callable argument could cause the test to appear to always pass. Initial patch by Kamilla Holanda.
* Close #19880: Fix a reference leak in unittest.TestCase. Explicitly breakVictor Stinner2013-12-091-1/+13
| | | | reference cycles between frames and the _Outcome instance.