summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test
Commit message (Collapse)AuthorAgeFilesLines
* [3.11] gh-106300: Improve errors testing in test_unittest.test_runner ↵Miss Islington (bot)2023-08-161-52/+65
| | | | | | | | (GH-106737) (GH-108007) Use a custom exception to prevent unintentional silence of actual errors. (cherry picked from commit fd9d70a94de5b0756b52b9ae21e236e25545db4f) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.11] gh-106300: Improve `assertRaises(Exception)` usages in tests ↵Serhiy Storchaka2023-07-081-2/+3
| | | | | | | (GH-106302). (GH-106545) (cherry picked from commit 6e6a4cd52332017b10c8d88fbbbfe015948093f4) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.11] gh-102978: Fix mock.patch function signatures for class and ↵Miss Islington (bot)2023-05-222-0/+48
| | | | | | | | | | | staticmethod decorators (GH-103228) (#103499) Fixes unittest.mock.patch not enforcing function signatures for methods decorated with @classmethod or @staticmethod when patch is called with autospec=True. (cherry picked from commit 59e0de4903c02e72b329e505fddf1ad9794928bc) Co-authored-by: Tomas R <tomas.roun8@gmail.com>
* gh-103329: Add regression test for PropertyMock with side effect (GH-103358)Miss Islington (bot)2023-04-081-1/+22
| | | | | (cherry picked from commit 26c65980dc6d842879d133165bb7c461d98cc6c7) Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
* gh-100739: Respect mock spec when checking for unsafe prefixes (GH-100740)Miss Islington (bot)2023-01-041-0/+16
| | | | | | (cherry picked from commit 7f1eefc6f4843f0fca60308f557a71af11d18a53) Co-authored-by: Christian Klein <167265+cklein@users.noreply.github.com> Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.11] gh-100287: Fix unittest.mock.seal with AsyncMock (GH-100496) (#100506)Shantanu2022-12-241-1/+13
| | | | | (cherry picked from commit e4b43ebb3afbd231a4e5630e7e358aa3093f8677) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* gh-98458: unittest: bugfix for infinite loop while handling chained ↵Miss Islington (bot)2022-12-041-0/+56
| | | | | | | | | | exceptions that contain cycles (GH-98459) * Bugfix addressing infinite loop while handling self-referencing chained exception in TestResult._clean_tracebacks() * Bugfix extended to properly handle exception cycles in _clean_tracebacks. The "seen" set follows the approach used in the TracebackException class (thank you @iritkatriel for pointing it out) * adds a test for a single chained exception that holds a self-loop in its __cause__ and __context__ attributes (cherry picked from commit 72ec518203c3f3577a5e888b12f10bb49060e6c2) Co-authored-by: AlexTate <0xalextate@gmail.com>
* [3.11] gh-99645: Fix a bug in handling class cleanups in unittest.TestCase ↵Serhiy Storchaka2022-11-221-0/+27
| | | | | | | | | (GH-99646) (GH-99698) Now addClassCleanup() uses separate lists for different TestCase subclasses, and doClassCleanups() only cleans up the particular class. (cherry picked from commit c2102136be569e6fc8ed90181f229b46d07142f8)
* Add more details in test_unittest (GH-99626)Miss Islington (bot)2022-11-212-35/+67
| | | | | (cherry picked from commit 653e563d80fabee8830e0b55f194f82a9beabe70) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.11] gh-98086: Now ``patch.dict`` can decorate async functions (GH-98095) ↵Miss Islington (bot)2022-11-191-0/+17
| | | | | | | | | | (#99365) gh-98086: Now ``patch.dict`` can decorate async functions (GH-98095) (cherry picked from commit 67b4d2772c5124b908f8ed9b13166a79bbeb88d2) Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.11] gh-97837: Change deprecation warning message in `unittest` (GH-97838) ↵Miss Islington (bot)2022-10-052-6/+28
| | | | | | | | | | (GH-97887) (cherry picked from commit c3648f4e4a12ec6efe65684facfcd08996e550ca) Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Automerge-Triggered-By: GH:orsenthil
* gh-96021: Explicitly close the IsolatedAsyncioTestCase runner in tests ↵Miss Islington (bot)2022-08-251-2/+7
| | | | | | | | | | | (GH-96135) Tests for IsolatedAsyncioTestCase.debug() rely on the runner be closed in __del__. It makes tests depending on the GC an unreliable on other implementations. It is better to close the runner explicitly even if currently there is no a public API for this. (cherry picked from commit 4de06e3cc0a58d73934f9a2759ad9cd2f6b031b0) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.11] GH-95736: fix IsolatedAsyncioTestCase to initialize Runner bef… ↵Kumar Aditya2022-08-181-0/+15
| | | | | | (#96042) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-45046: Support context managers in unittest (GH-28045)Miss Islington (bot)2022-05-082-0/+163
| | | | | | | | Add methods enterContext() and enterClassContext() in TestCase. Add method enterAsyncContext() in IsolatedAsyncioTestCase. Add function enterModuleContext(). (cherry picked from commit 086c6b1b0fe8d47ebd15512d7bdcb64c60a360f0) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-57684: Update tests for PYTHONSAFEPATH=1 (#92358)Victor Stinner2022-05-061-1/+3
| | | | | Fix tests failing with the PYTHONSAFEPATH=1 env var. Enhance also -P help in Python usage (python --help).
* Simplify testing the warning filename (GH-91868)Serhiy Storchaka2022-04-243-15/+15
| | | The context manager result has the "filename" attribute.
* bpo-14265: Adds fully qualified test name to unittest output (GH-32138)Sam Ezeh2022-03-291-34/+40
| | | Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
* bpo-40280: Skip socket, fork, subprocess tests on Emscripten (GH-31986)Christian Heimes2022-03-225-1/+12
| | | | | | | | | | | - Add requires_fork and requires_subprocess to more tests - Skip extension import tests if dlopen is not available - Don't assume that _testcapi is a shared extension - Skip a lot of socket tests that don't work on Emscripten - Skip mmap tests, mmap emulation is incomplete - venv does not work yet - Cannot get libc from executable The "entire" test suite is now passing on Emscripten with EMSDK from git head (91 suites are skipped).
* bpo-46994: Accept explicit contextvars.Context in asyncio create_task() API ↵Andrew Svetlov2022-03-141-0/+18
| | | | (GH-31837)
* bpo-24959: fix unittest.assertRaises bug where traceback entries are dropped ↵Irit Katriel2022-03-081-0/+55
| | | | from chained exceptions (GH-23688)
* bpo-46709: check eval breaker in specialized `CALL` opcodes (GH-31404)Nikita Sobolev2022-02-181-59/+85
|
* Restrict use of Mock objects as specs (GH-31090)Matthew Suozzo2022-02-032-2/+10
| | | | | Follow-on to https://github.com/python/cpython/pull/25326 This covers cases where mock objects are passed directly to spec.
* bpo-45162: Revert "Remove many old deprecated unittest features" (GH-30935)Gregory P. Smith2022-01-276-24/+238
| | | | | | | | | | 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-41403: Improve error message for invalid mock target (GH-30833)Irit Katriel2022-01-231-2/+7
|
* bpo-46425: Fix direct invocation of multiple test modules (GH-30666)Nikita Sobolev2022-01-181-1/+1
|
* bpo-23882: unittest: Drop PEP 420 support from discovery. (GH-29745)Inada Naoki2022-01-101-33/+2
|
* bpo-22815: Print unexpected successes in summary in TextTestResult (GH-30138)Serhiy Storchaka2021-12-261-8/+32
|
* bpo-46111: Fix unittest tests in optimized mode (GH-30163)Serhiy Storchaka2021-12-173-3/+6
|
* bpo-13236: Flush the output stream more often in unittest (GH-29864)Serhiy Storchaka2021-12-042-5/+46
| | | It can prevent some losses when output to buffered stream.
* Fix typos in the Lib directory (GH-28775)Christian Clauss2021-10-061-1/+1
| | | | | Fix typos in the Lib directory as identified by codespell. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* bpo-45238: Fix unittest.IsolatedAsyncioTestCase.debug() (GH-28449)Serhiy Storchaka2021-09-221-51/+155
| | | | | | 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-195-29/+40
| | | | | | | 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-0/+66
| | | | | | | | 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-176-238/+24
| | | | | | | * "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-5846: Fix deprecations for obsolete unittest functions and add tests. ↵Serhiy Storchaka2021-09-171-0/+47
| | | | (GH-28382)
* bpo-45156: Fixes inifite loop on unittest.mock.seal() (GH-28300)Nikita Sobolev2021-09-141-0/+61
| | | | | | Fixes infinite loop on unittest.mock.seal() of mocks created by unittest.create_autospec(). Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
* bpo-5846: Do not use obsolete unittest functions. (GH-28303)Serhiy Storchaka2021-09-131-1/+1
| | | | Get rid of use of makeSuite() and findTestCases(). Also make test_math and test_threading_local discoverable.
* bpo-25894: Always report skipped and failed subtests separately (GH-28082)Serhiy Storchaka2021-09-101-45/+151
| | | | | | * In default mode output separate characters for skipped and failed subtests. * In verbose mode output separate lines (including description) for skipped and failed subtests. * In verbose mode output test description for errors in test cleanup.
* bpo-45102: unittest: add tests for skipping and errors in cleanup (GH-28166)Serhiy Storchaka2021-09-051-0/+138
|
* bpo-43913: Fix bugs in cleaning up classes and modules in unittest. (GH-28006)Serhiy Storchaka2021-08-302-9/+632
| | | | | | | | | | | | | | * Functions registered with addModuleCleanup() were not called unless the user defines tearDownModule() in their test module. * Functions registered with addClassCleanup() were not called if tearDownClass is set to None. * Buffering in TestResult did not work with functions registered with addClassCleanup() and addModuleCleanup(). * Errors in functions registered with addClassCleanup() and addModuleCleanup() were not handled correctly in buffered and debug modes. * Errors in setUpModule() and functions registered with addModuleCleanup() were reported in wrong order. * And several lesser bugs.
* bpo-41620: TestCase.run() now always return a TestResult instance (GH-28030)Serhiy Storchaka2021-08-301-23/+30
| | | | | | 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-25130: Add calls of gc.collect() in tests to support PyPy (GH-28005)Serhiy Storchaka2021-08-292-1/+5
|
* bpo-41322: Add unit tests for deprecation of test return values (GH-27846)andrei kulakov2021-08-222-0/+40
| | | | Also fix the traceback of warnings.
* bpo-44955: Always call stopTestRun() for implicitly created TestResult ↵Serhiy Storchaka2021-08-221-1/+49
| | | | | | | | 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-44911: Fixed IsolatedAsyncioTestCase from throwing an exception on ↵Bar Harel2021-08-161-0/+20
| | | | leaked tasks (GH-27765)
* bpo-44017: Update test_contextlib_async not to emit DeprecationWarn (GH-25918)Dong-hee Na2021-05-061-2/+1
|
* bpo-43478: Restrict use of Mock objects as specs (GH-25326)Matthew Suozzo2021-04-102-4/+26
| | | | * Restrict using Mock objects as specs as this is always a test bug where the resulting mock is misleadingly useless. * Skip a broken test that exposes a bug elsewhere in mock (noted in the original issue).
* bpo-41877: Check for misspelled speccing arguments (GH-23737)vabr-g2020-12-141-0/+52
| | | | | | | | | | | | patch, patch.object and create_autospec silently ignore misspelled arguments such as autospect, auto_spec and set_spec. This can lead to tests failing to check what they are supposed to check. This change adds a check causing a RuntimeError if the above functions get any of the above misspellings as arguments. It also adds a new argument, "unsafe", which can be set to True to disable this check. Also add "!r" to format specifiers in added error messages.
* bpo-41877: Improve docs for assert misspellings check in mock (GH-23729)vabr-g2020-12-101-1/+1
| | | | | | | | | This is a follow-up to https://github.com/python/cpython/commit/4662fa9bfe4a849fe87bfb321d8ef0956c89a772. That original commit expanded guards against misspelling assertions on mocks. This follow-up updates the documentation and improves the error message by pointing out the potential cause and solution. Automerge-Triggered-By: GH:gpshead
* bpo-42532: Check if NonCallableMock's spec_arg is not None instead of call ↵idanw2062020-12-061-0/+10
| | | | | | its __bool__ function (GH23613) Check if NonCallableMock's spec_arg is not None instead of call its __bool__ function