Commit graph

591 commits

Author SHA1 Message Date
Miss Islington (bot)
51b62fb25a
[3.12] gh-124234: Improve docs for Mock.reset_mock (GH-124237) (#124592)
gh-124234: Improve docs for `Mock.reset_mock` (GH-124237)
(cherry picked from commit 19fed6cf6e)

Co-authored-by: sobolevn <mail@sobolevn.me>
2024-09-26 12:24:27 +00:00
Miss Islington (bot)
e9578f6424
[3.12] gh-123934: Fix MagicMock not to reset magic method return values (GH-124038) (#124232)
gh-123934: Fix `MagicMock` not to reset magic method return values (GH-124038)
(cherry picked from commit 7628f67d55)

Co-authored-by: sobolevn <mail@sobolevn.me>
2024-09-19 08:18:01 +00:00
Miss Islington (bot)
34ace5ba4c
[3.12] gh-120732: Fix name passing to Mock, when using kwargs to create_autospec (GH-120737) (#120761)
gh-120732: Fix `name` passing to `Mock`, when using kwargs to `create_autospec` (GH-120737)
(cherry picked from commit 1e4815692f)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-06-19 20:53:19 +00:00
Miss Islington (bot)
f6481925d8
[3.12] gh-65454: avoid triggering call to a PropertyMock in NonCallableMock.__setattr__ (GH-120019) (#120337)
gh-65454: avoid triggering call to a PropertyMock in NonCallableMock.__setattr__ (GH-120019)
(cherry picked from commit 9e9ee50421)

Co-authored-by: blhsing <blhsing@gmail.com>
2024-06-11 06:07:25 +00:00
Miss Islington (bot)
fa291a35eb
[3.12] gh-119600: mock: do not access attributes of original when new_callable is set (GH-119601) (#120335)
gh-119600: mock: do not access attributes of original when new_callable is set (GH-119601)

In order to patch flask.g e.g. as in GH-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.
(cherry picked from commit 422c4fc855)

Co-authored-by: Robert Collins <robert.collins@cognite.com>
2024-06-11 06:01:02 +00:00
Miss Islington (bot)
23ba96e243
[3.12] gh-90848: Fixed create_autospec ignoring configure_mock style kwargs (GH-118163) (#118517)
gh-90848: Fixed create_autospec ignoring configure_mock style kwargs (GH-118163)
(cherry picked from commit b28a3339e4)

Co-authored-by: infohash <46137868+infohash@users.noreply.github.com>
2024-05-02 18:01:17 +00:00
Miss Islington (bot)
fbe29e639d
[3.12] gh-59215: unittest: restore _top_level_dir at end of discovery (GH-15242) (GH-117508)
* gh-59215: unittest: restore _top_level_dir at end of discovery (GH-15242)
(cherry picked from commit fc5f68e58e)


Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-04-23 12:41:32 +00:00
infohash
ad0ff86034
[3.12] gh-75988: Fix issues with autospec ignoring wrapped object (GH-115223) (#117119)
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

(cherry picked from commit 735fc2cbbc)
2024-03-22 09:47:52 +00:00
Miss Islington (bot)
0a737639dc
[3.12] gh-113267: Revert "gh-106584: Fix exit code for unittest in Python 3.12 (GH-106588)" (GH-114470) (GH-114994)
This reverts commit 8fc071345b.
(cherry picked from commit ecabff98c4)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-02-04 16:00:56 +00:00
Miss Islington (bot)
159e3db1f7
[3.12] GH-113661: unittest runner: Don't exit 5 if tests were skipped (GH-113856) (#113875)
GH-113661: unittest runner: Don't exit 5 if tests were skipped (GH-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.
(cherry picked from commit 3a9096c337)

Co-authored-by: Stefano Rivera <stefano@rivera.za.net>
2024-01-09 13:34:38 -08:00
Miss Islington (bot)
bd306a9299
[3.12] gh-113407: Fix import of unittest.mock when CPython is built without docstrings (GH-113408) (GH-113454)
(cherry picked from commit 0c574540e0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-12-24 11:54:35 +00:00
Miss Islington (bot)
577a8fb72b
[3.12] gh-111019: Align expected and actual titles in test output (GH-111020) (#111024)
gh-111019: Align expected and actual titles in test output (GH-111020)

Align expected and actual titles in output from
assert_has_calls/assert_called_with for greater readability
(cherry picked from commit 77dbd95609)

Co-authored-by: James <morisja@gmail.com>
2023-10-18 08:01:18 +00:00
Miss Islington (bot)
551aa6ab94
[3.12] gh-106584: Fix exit code for unittest in Python 3.12 (GH-106588) (#109725)
gh-106584: Fix exit code for unittest in Python 3.12 (GH-106588)
(cherry picked from commit 8fc071345b)

Co-authored-by: EliseevEgor <egor.eliseev@jetbrains.com>
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-10-02 17:18:41 +02:00
Miss Islington (bot)
2fb39f73ed
[3.12] gh-84867: Do not load tests from TestCase and FunctionTestCase (GH-100497) (#109327)
gh-84867: Do not load tests from TestCase and FunctionTestCase (GH-100497)
(cherry picked from commit 66d1d7eb06)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-10-02 16:57:44 +02:00
Miss Islington (bot)
b1c50b80a6
[3.12] gh-104090: Fix unittest collectedDurations resources leak (GH-106795) (#106888)
gh-104090: Fix unittest collectedDurations resources leak (GH-106795)
(cherry picked from commit 70b961ed93)

Co-authored-by: Yonatan Bitton <bityob@gmail.com>
2023-07-19 11:34:54 +00:00
Michael Blahay
46361bb843
gh-68968: Correcting message display issue with assertEqual (#103937) 2023-05-04 16:37:17 -06:00
Stefano Rivera
76632b836c
gh-62432: unittest runner: Exit code 5 if no tests were run (#102051)
As discussed in https://discuss.python.org/t/unittest-fail-if-zero-tests-were-discovered/21498/7

It is common for test runner misconfiguration to fail to find any tests,
This should be an error.

Fixes: #62432
2023-04-27 01:28:46 +00:00
Giampaolo Rodola
ff3303e49c
gh-48330: address review comments to PR-12271 (#103209)
address review comments to PR-12271

Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
2023-04-17 00:19:44 +02:00
Tomas R
59e0de4903
gh-102978: Fix mock.patch function signatures for class and staticmethod decorators (#103228)
Fixes unittest.mock.patch not enforcing function signatures for methods
decorated with @classmethod or @staticmethod when patch is called with
autospec=True.
2023-04-13 08:37:57 +01:00
Giampaolo Rodola
6883007a86
bpo-4080: unittest durations (#12271) 2023-04-03 00:12:51 +02:00
JosephSBoyle
c84e6f32df
Remove unused import of warnings from unittest.loader (#102479) 2023-03-06 22:02:19 +00:00
Nikita Sobolev
9e7d7266ec
gh-96127: Fix inspect.signature call on mocks (#96335) 2023-01-07 10:49:15 +00:00
Nikita Sobolev
a109454e82
gh-100690: [mock] hide ATTRIB_DENY_LIST and make it immutable (#100819) 2023-01-07 10:25:05 +00:00
Christian Klein
1d4d677d1c
gh-100690: Raise an AttributeError when the assert_ prefix is forgotten when using Mock (#100691)
Mock objects which are not unsafe will now raise an AttributeError when accessing an
attribute that matches the name of an assertion but without the prefix `assert_`, e.g. accessing `called_once` instead of `assert_called_once`.

This is in addition to this already happening for accessing attributes with prefixes assert, assret, asert, aseert, and assrt.
2023-01-06 18:38:50 +00:00
Christian Klein
7f1eefc6f4
gh-100739: Respect mock spec when checking for unsafe prefixes (#100740)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-01-04 22:31:29 +00:00
Shantanu
e4b43ebb3a
gh-100287: Fix unittest.mock.seal with AsyncMock (#100496) 2022-12-24 19:39:39 +00:00
Nikita Sobolev
745545b5bb
gh-99482: remove jython compatibility parts from stdlib and tests (#99484) 2022-12-23 14:17:24 -06:00
Carl Meyer
c5726b727e
gh-83076: 3.8x speed improvement in (Async)Mock instantiation (#100252) 2022-12-23 19:41:37 +00:00
AlexTate
72ec518203
gh-98458: unittest: bugfix for infinite loop while handling chained exceptions that contain cycles (#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
2022-12-04 11:37:55 -08:00
Serhiy Storchaka
c2102136be
gh-99645: Fix a bug in handling class cleanups in unittest.TestCase (GH-99646)
Now addClassCleanup() uses separate lists for different TestCase subclasses,
and doClassCleanups() only cleans up the particular class.
2022-11-22 17:49:37 +02:00
Nikita Sobolev
67b4d2772c
gh-98086: Now `patch.dict` can decorate async functions (#98095) 2022-11-11 08:04:30 +00:00
andrei kulakov
c6325b1c9f
gh-91803: Mock - fix error when using autospec methods with seal (#92213)
Fixes https://github.com/python/cpython/issues/91803.

Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2022-11-07 07:24:46 +00:00
noah-weingarden
0346eddbe9
gh-98624 Add mutex to unittest.mock.NonCallableMock (#98688)
* Added lock to NonCallableMock in unittest.mock

* Add blurb

* Nitpick blurb

* Edit comment based on @Jason-Y-Z's review

* Add link to GH issue
2022-10-28 08:51:18 +01:00
Nikita Sobolev
c3648f4e4a
gh-97837: Change deprecation warning message in unittest (#97838) 2022-10-04 17:29:18 -07:00
Serhiy Storchaka
36517101dd
gh-95736: Fix event loop creation in IsolatedAsyncioTestCase (GH-96033)
It should be created before calling the setUp() method, but after
checking for skipping a test.

Automerge-Triggered-By: GH:tiran
2022-08-17 02:05:17 -07:00
Kumar Aditya
9d515997f9
GH-95736: fix IsolatedAsyncioTestCase to initialize Runner before calling setup functions (#95898) 2022-08-16 08:52:06 -07:00
Mehdi ABAAKOUK
4261b6bffc
gh-84753: Make inspect.iscoroutinefunction() work with AsyncMock (#94050)
The inspect version was not working with unittest.mock.AsyncMock.

The fix introduces special-casing of AsyncMock in
`inspect.iscoroutinefunction` equivalent to the one
performed in `asyncio.iscoroutinefunction`.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2022-06-30 19:08:38 +02:00
Serhiy Storchaka
c834c02569
Revert "bpo-45162: Revert "Remove many old deprecated unittest features"" (GH-92556)
This reverts commit b50322d203.
2022-06-26 10:18:06 +03:00
Victor Stinner
c735d54534
gh-93839: Move Lib/unttest/test/ to Lib/test/test_unittest/ (#94043)
* Move Lib/unittest/test/ to Lib/test/test_unittest/
* Remove Lib/test/test_unittest.py
* Replace unittest.test with test.test_unittest
* Remove unittest.load_tests()
* Rewrite unittest __init__.py and __main__.py
* Update build system, CODEOWNERS, and wasm_assets.py
2022-06-21 10:27:59 +02:00
Serhiy Storchaka
086c6b1b0f
bpo-45046: Support context managers in unittest (GH-28045)
Add methods enterContext() and enterClassContext() in TestCase.
Add method enterAsyncContext() in IsolatedAsyncioTestCase.
Add function enterModuleContext().
2022-05-08 17:49:09 +03:00
Victor Stinner
329afe78c3
gh-57684: Update tests for PYTHONSAFEPATH=1 (#92358)
Fix tests failing with the PYTHONSAFEPATH=1 env var.

Enhance also -P help in Python usage (python --help).
2022-05-06 03:41:24 +02:00
Serhiy Storchaka
090721721b
Simplify testing the warning filename (GH-91868)
The context manager result has the "filename" attribute.
2022-04-24 10:23:59 +03:00
Sam Ezeh
755be9b150
bpo-14265: Adds fully qualified test name to unittest output (GH-32138)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2022-03-29 18:02:09 +03:00
Andrew Svetlov
4119d2d7c9
bpo-47062: Implement asyncio.Runner context manager (GH-31799)
Co-authored-by: Zachary Ware <zach@python.org>
2022-03-24 21:51:16 +02:00
Christian Heimes
deeaac49e2
bpo-40280: Skip socket, fork, subprocess tests on Emscripten (GH-31986)
- 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).
2022-03-22 03:04:36 -07:00
Bader Zaidan
a0db11b10f
bpo-46421: Fix unittest filename evaluation when called as a module (GH-30654) 2022-03-17 16:37:52 -07:00
Carlos Damazio
7c353b7594
bpo-22859: deprecate unittest.main.TestProgram.usageExit (GH-30293)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-03-16 19:41:02 -07:00
Andrew Svetlov
9523c0d84f
bpo-46994: Accept explicit contextvars.Context in asyncio create_task() API (GH-31837) 2022-03-14 13:54:13 +02:00
Irit Katriel
88b7d86a73
bpo-24959: fix unittest.assertRaises bug where traceback entries are dropped from chained exceptions (GH-23688) 2022-03-08 21:43:49 +00:00
Kumar Aditya
cc400585fa
bpo-46877: export unittest.doModuleCleanups in unittest package (#31613) 2022-03-03 10:41:28 -08:00