Commit Graph

97 Commits

Author SHA1 Message Date
Miss Islington (bot) 3daf1fad7a [3.15] gh-149189: Revert "Modern defaults for pprint (GH-149190)" (GH-150249) (#150268)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-05-22 20:49:36 +00:00
Hugo van Kemenade 426f99cb71 gh-149189: Modern defaults for pprint (#149190) 2026-05-05 15:04:05 +03:00
Serhiy Storchaka a3435d5ccc gh-143231: Do not swallow not matched warnings in assertWarns*() (GH-149229)
unittest.TestCase methods assertWarns() and assertWarnsRegex() no longer
swallow warnings that do not match the specified category or regex.
Nested context managers are now supported.
2026-05-03 10:24:57 +00:00
Matthias Schoettle d357a7dbf3 gh-145754: Update signature retrieval in unittest.mock to use forwardref annotation format (#145756) 2026-03-19 19:39:41 -07:00
Stefan Zetzsche ece712197d gh-145546: unittest.util: fix sorted_list_difference tail deduplication (GH-145547)
* fix(unittest.util): Deduplicate tail elements in sorted_list_difference

sorted_list_difference failed to deduplicate remaining elements when one
list was exhausted, causing duplicate values in the result.

Deduplicate before extending.

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2026-03-11 13:21:22 +01:00
Kumar Aditya 4fd006e712 gh-142752: add more thread safety tests for mock (#142791) 2025-12-17 13:17:12 +05:30
chaope 850f95f6f6 gh-142651: make Mock.call_count thread-safe (#142656) 2025-12-15 17:13:15 +05:30
Takuya UESHIN 53d65c840e gh-136442: Fix unittest to return exit code 5 when setUpClass raises an exception (#136487) 2025-11-14 16:59:51 -08:00
Jelle Zijlstra 797abd1f7f gh-134657: Remove newly added private names from asyncio.__all__ (#134665) 2025-07-09 13:25:46 +05:30
Garry Cairns 51ab66b3d5 gh-134567: Add the formatter parameter in unittest.TestCase.assertLogs (GH-134570) 2025-07-02 09:51:19 +00:00
sobolevn c8319a3fea gh-135368: Fix mocks on dataclass specs with instance=True (#135421)
* gh-135368: Fix mocks on dataclass specs with `instance=True`

* Extend dataclass mock_methods

---------

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2025-06-14 09:46:43 +01:00
Serhiy Storchaka 393773ae87 gh-134565: Use ExceptionGroup to handle multiple errors in unittest.doModuleCleanups() (GH-134566) 2025-05-23 21:07:49 +03:00
Serhiy Storchaka 2602d8ae98 gh-71339: Use new assertion methods in tests (GH-129046) 2025-05-22 13:17:22 +03:00
Kumar Aditya 05d27a84f4 gh-130322: drop deprecation of asyncio.set_event_loop (#132349) 2025-04-12 12:03:52 +05:30
Chris Withers 04091c0833 unittest.mock test and coverage fixup (#130787)
* Mark functions that will never be called with # pragma: no cover

* Fix testpatch.PatchTest.test_exit_idempotent

.stop() and __exit__ have subtly different code paths, so to really test __exit__ idempotency, we need to call it specifically twice.
2025-03-03 11:44:59 +00:00
Hugo van Kemenade 05d12eecbd gh-127873: Only check sys.flags.ignore_environment for PYTHON* env vars (#127877) 2025-01-21 16:10:08 +00:00
Serhiy Storchaka 4b37a6bda2 gh-71339: Fix an order-dependent failure in test_unittest (GH-129133)
It failed if it was preceded by test_builtin.
2025-01-21 16:45:20 +02:00
Serhiy Storchaka da122b5fac gh-71339: Improve error report for types in assertHasAttr() and assertNotHasAttr() (GH-128818) 2025-01-20 11:17:49 +02:00
Serhiy Storchaka 06cad77a5b gh-71339: Add additional assertion methods for unittest (GH-128707)
Add the following methods:

* assertHasAttr() and assertNotHasAttr()
* assertIsSubclass() and assertNotIsSubclass()
* assertStartsWith() and assertNotStartsWith()
* assertEndsWith() and assertNotEndsWith()

Also improve error messages for assertIsInstance() and
assertNotIsInstance().
2025-01-14 10:02:38 +02:00
Hugo van Kemenade afb9dc887c gh-128595: Add test class helper to force no terminal colour (#128687)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2025-01-13 11:05:02 +00:00
Serhiy Storchaka cb72feb8a3 gh-128729: Fix RuntimeWarning in test_unittest (GH-128730) 2025-01-12 12:22:43 +02:00
Kumar Aditya 9fce906825 gh-127949: deprecate asyncio.set_event_loop (#128218)
Deprecate `asyncio.set_event_loop` to be removed in Python 3.16.
2024-12-24 19:24:28 +05:30
Kumar Aditya dbd08fb60d gh-127949: deprecate asyncio.get_event_loop_policy (#128053)
This deprecates `asyncio.get_event_loop_policy` and will be removed in Python 3.16.
2024-12-18 18:04:20 +05:30
Kumar Aditya 5892853fb7 gh-127949: deprecate asyncio.set_event_loop_policy (#128024)
First step towards deprecating the asyncio policy system.
This deprecates `asyncio.set_event_loop_policy` and will be removed in Python 3.16.
2024-12-18 11:35:29 +05:30
Hugo van Kemenade 23f2e8f13c gh-127221: Add colour to unittest output (#127223)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-12-05 21:10:46 +02:00
Red4Ru 1e40c5ba47 gh-104745: Limit starting a patcher more than once without stopping it (#126649)
Previously, this would cause an `AttributeError` if the patch stopped more than once after this, and would also disrupt the original patched object.

---------

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-11-13 08:20:38 +00:00
Jacob Walls c75ff2ef8e gh-80958: unittest: discovery support for namespace packages as start directory (#123820) 2024-10-23 13:41:33 +09:00
Irit Katriel e97910cdb7 gh-125522 : add explicit exception types to bare excepts in tests (#125523) 2024-10-15 17:00:04 +01:00
sobolevn 3a0e7f5762 gh-124176: Add special support for dataclasses to create_autospec (#124429) 2024-09-27 09:48:31 +03:00
sobolevn 7628f67d55 gh-123934: Fix MagicMock not to reset magic method return values (#124038) 2024-09-19 10:55:47 +03:00
Kirill Podoprigora e6d5ff55d0 gh-123087: `Lib/test/test_unittest/testmock/testasync.py: Replace usage of the deprecated asyncio.iscoroutinefunction with the inspect.iscoroutinefunction` (#123088)
asyncio.iscoroutinefunction -> inspect.iscoroutinefunction
2024-08-17 11:03:51 +03:00
Wulian bc9d92c679 gh-122858: Deprecate asyncio.iscoroutinefunction (#122875)
Deprecate `asyncio.iscoroutinefunction` in favor of `inspect.iscoroutinefunction`.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-08-11 16:35:51 +00:00
Tomas R 901ea411bf gh-121708: Improve test coverage for unittest.util (GH-121713) 2024-07-14 10:08:47 +02:00
Nikita Sobolev 1e4815692f gh-120732: Fix name passing to Mock, when using kwargs to create_autospec (#120737) 2024-06-19 21:35:11 +01:00
Nikita Sobolev 42ebdd83bb gh-120544: Add else: fail() to tests where exception is expected (#120545) 2024-06-15 10:33:14 +00:00
Nikita Sobolev fabcf6bc8f gh-120388: Improve deprecation warning message, when test returns non-None (#120401)
Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-06-12 14:50:58 +00:00
blhsing 9e9ee50421 gh-65454: avoid triggering call to a PropertyMock in NonCallableMock.__setattr__ (#120019) 2024-06-11 05:42:49 +00:00
Robert Collins 422c4fc855 gh-119600: mock: do not access attributes of original when new_callable is set (#119601)
In order to patch flask.g e.g. as in #84982, that
proxies getattr must not be invoked. For that,
mock must not try to read from the original
object. In some cases that is unavoidable, e.g.
when doing autospec. However, patch("flask.g",
new_callable=MagicMock) should be entirely safe.
2024-06-11 06:41:12 +01:00
infohash b28a3339e4 gh-90848: Fixed create_autospec ignoring configure_mock style kwargs (#118163) 2024-05-02 18:36:35 +01:00
Serhiy Storchaka c0eaa232f6 gh-117860: Add tests for resolving names when import rebind names (GH-118176)
Add tests for "import", pkgutil.resolve_name() and unittest.mock.path()
for cases when "import a.b as x" and "from a import b as x" give
different results.
2024-04-30 17:23:44 +03:00
Zackery Spytz fc5f68e58e gh-59215: unittest: restore _top_level_dir at end of discovery (GH-15242) 2024-04-03 16:17:13 +02:00
Gregory P. Smith 33ee5cb3e9 GH-70647: Deprecate strptime day of month parsing without a year present to avoid leap-year bugs (GH-117107) 2024-04-03 14:19:49 +02:00
infohash 735fc2cbbc gh-75988: Fix issues with autospec ignoring wrapped object (#115223)
* set default return value of functional types as _mock_return_value

* added test of wrapping child attributes

* added backward compatibility with explicit return

* added docs on the order of precedence

* added test to check default return_value
2024-03-08 19:14:32 +00:00
Nikita Sobolev f8e9c57067 gh-115274: Fix direct invocation of testmock/testpatch.py (#115275) 2024-02-11 11:51:25 +03:00
Serhiy Storchaka ecabff98c4 gh-113267: Revert "gh-106584: Fix exit code for unittest in Python 3.12 (#106588)" (GH-114470)
This reverts commit 8fc071345b.
2024-02-04 17:27:42 +02:00
Barney Gale e4ff131e01 GH-44626, GH-105476: Fix ntpath.isabs() handling of part-absolute paths (#113829)
On Windows, `os.path.isabs()` now returns `False` when given a path that
starts with exactly one (back)slash. This is more compatible with other
functions in `os.path`, and with Microsoft's own documentation.

Also adjust `pathlib.PureWindowsPath.is_absolute()` to call
`ntpath.isabs()`, which corrects its handling of partial UNC/device paths
like `//foo`.

Co-authored-by: Jon Foster <jon@jon-foster.co.uk>
2024-01-13 07:36:05 +00:00
Stefano Rivera 3a9096c337 GH-113661: unittest runner: Don't exit 5 if tests were skipped (#113856)
The intention of exiting 5 was to detect issues where the test suite
wasn't discovered at all. If we skipped tests, it was correctly
discovered.
2024-01-09 19:50:01 +00:00
wookie184 1600d78e2d gh-113569: Display calls in Mock.assert_has_calls failure when empty (GH-113573) 2024-01-04 21:11:34 +02:00
Thomas Grainger 770530679e gh-110774: allow setting the Runner(loop_factory=...) from IsolatedAsyncioTestCase (#110776)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2023-10-31 15:03:54 -07:00
James 77dbd95609 gh-111019: Align expected and actual titles in test output (#111020)
Align expected and actual titles in output from
assert_has_calls/assert_called_with for greater readability
2023-10-18 08:36:16 +01:00