Skip to content

bpo-41403: Improve error message for invalid mock target - #30833

Merged
iritkatriel merged 3 commits into
python:mainfrom
iritkatriel:bpo-41403
Jan 23, 2022
Merged

bpo-41403: Improve error message for invalid mock target#30833
iritkatriel merged 3 commits into
python:mainfrom
iritkatriel:bpo-41403

Conversation

@iritkatriel

@iritkatrieliritkatriel commented Jan 23, 2022

Copy link
Copy Markdown
Member

Comment threadLib/unittest/mock.py Outdated
Comment on lines 1593 to 1594
raise TypeError("Need a valid target to patch. You supplied: %r" %
(target,))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raiseTypeError("Need a valid target to patch. You supplied: %r"%
(target,))
raiseTypeError(f"Need a valid target to patch. You supplied: {target}")

since there is a change of nearby lines anyway. Plus, "b'%r' is deprecated, but will not be removed during the 3.x series" in the docs.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be {target!r} I suppose?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. I was optimistic seeing string-only nature of target:

`target` should be a string in the form `'package.module.ClassName'`. The

Like, once it was an object requiring some special formatting but now it's just a string. However, I forgot that %r additionally escapes non-ascii code points.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, also this bpo is about the case where the error is that you passed in some non-string object.

@iritkatrieliritkatriel added needs backport to 3.9 needs backport to 3.10 only security fixes type-bug An unexpected behavior, bug, or error labels Jan 23, 2022
@iritkatriel
iritkatriel merged commit f7955a8 into python:mainJan 23, 2022
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @iritkatriel for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry @iritkatriel, I had trouble checking out the 3.10 backport branch.
Please backport using cherry_picker on command line.
cherry_picker f7955a82e36d4c32ebdd7b7707cdf0e6ffa7a418 3.10

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @iritkatriel, I could not cleanly backport this to 3.9 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker f7955a82e36d4c32ebdd7b7707cdf0e6ffa7a418 3.9

iritkatriel added a commit that referenced this pull request Jan 23, 2022
@bedevere-bot

Copy link
Copy Markdown

GH-30834 is a backport of this pull request to the 3.10 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.10 only security fixes label Jan 23, 2022
iritkatriel added a commit that referenced this pull request Jan 23, 2022
@bedevere-bot

Copy link
Copy Markdown

GH-30835 is a backport of this pull request to the 3.9 branch.

@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM64 macOS 3.x has failed when building commit f7955a8.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/725/builds/830) and take a look at the build logs.
  4. Check if the failure is related to this commit (f7955a8) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/725/builds/830

Summary of the results of the build (if available):

== Tests result: ENV CHANGED ==

411 tests OK.

10 slowest tests:

  • test_concurrent_futures: 3 min 36 sec
  • test_multiprocessing_spawn: 2 min 35 sec
  • test_multiprocessing_forkserver: 1 min 51 sec
  • test_unparse: 1 min 26 sec
  • test_asyncio: 1 min 20 sec
  • test_tokenize: 1 min 14 sec
  • test_nntplib: 1 min 1 sec
  • test_logging: 60.0 sec
  • test_capi: 52.9 sec
  • test_lib2to3: 52.8 sec

1 test altered the execution environment:
test_ftplib

17 tests skipped:
test_dbm_gnu test_devpoll test_epoll test_gdb test_ioctl
test_msilib test_multiprocessing_fork test_ossaudiodev test_spwd
test_startfile test_tix test_tk test_ttk_guionly test_winconsoleio
test_winreg test_winsound test_zipfile64

Total duration: 9 min 33 sec

Click to see traceback logs
Traceback (most recent call last):
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/multiprocessing/resource_tracker.py", line 209, in main
cache[rtype].remove(name)
^^^^^^^^^^^^^^^^^^^^^^^^^KeyError: '/psm_6579efa7'
Traceback (most recent call last):
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/asyncore.py", line 90, in read
obj.handle_read_event()
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_ftplib.py", line 384, in handle_read_eventself._do_ssl_handshake()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_ftplib.py", line 345, in _do_ssl_handshakeself.socket.do_handshake()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/ssl.py", line 1345, in do_handshakeself._sslobj.do_handshake()
^^^^^^^^^^^^^^^^^^^^^^^^^^^ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:998)
Traceback (most recent call last):
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/multiprocessing/resource_tracker.py", line 209, in main
cache[rtype].remove(name)
^^^^^^^^^^^^^^^^^^^^^^^^^KeyError: '/psm_360b6c08'
Traceback (most recent call last):
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/threading.py", line 1031, in _bootstrap_innerself.run()
^^^^^^^^^^
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_ftplib.py", line 298, in run
asyncore.loop(timeout=0.1, count=1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/asyncore.py", line 214, in loop
poll_fun(timeout, map)
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/asyncore.py", line 157, in poll
read(obj)
^^^^^^^^^
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/asyncore.py", line 94, in read
obj.handle_error()
^^^^^^^^^^^^^^^^^^
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_ftplib.py", line 421, in handle_errorraiseException^^^^^^^^^^^^^^^
Exception
k

@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM64 Windows Non-Debug 3.x has failed when building commit f7955a8.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/730/builds/2836) and take a look at the build logs.
  4. Check if the failure is related to this commit (f7955a8) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/730/builds/2836

Summary of the results of the build (if available):

== Tests result: ENV CHANGED ==

394 tests OK.

10 slowest tests:

  • test_peg_generator: 4 min 14 sec
  • test_multiprocessing_spawn: 1 min 57 sec
  • test_concurrent_futures: 1 min 34 sec
  • test_asyncio: 1 min 9 sec
  • test_socket: 1 min
  • test_mmap: 58.0 sec
  • test_distutils: 48.9 sec
  • test_io: 40.1 sec
  • test_urllib2_localnet: 38.3 sec
  • test_largefile: 34.6 sec

1 test altered the execution environment:
test_asyncio

37 tests skipped:
test_curses test_dbm_gnu test_dbm_ndbm test_devpoll test_epoll
test_fcntl test_fork1 test_gdb test_grp test_idle test_ioctl
test_kqueue test_multiprocessing_fork
test_multiprocessing_forkserver test_nis test_openpty
test_ossaudiodev test_pipes test_poll test_posix test_pty test_pwd
test_readline test_resource test_spwd test_syslog test_tcl
test_threadsignals test_tix test_tk test_ttk_guionly
test_ttk_textonly test_turtle test_wait3 test_wait4
test_xxtestfuzz test_zipfile64

Total duration: 13 min 49 sec

Click to see traceback logs
Traceback (most recent call last):
File "C:\Workspace\buildarea\3.x.linaro-win-arm64.nondebug\build\Lib\asyncio\proactor_events.py", line 116, in __del__self.close()
^^^^^^^^^^^^
File "C:\Workspace\buildarea\3.x.linaro-win-arm64.nondebug\build\Lib\asyncio\proactor_events.py", line 108, in closeself._loop.call_soon(self._call_connection_lost, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Workspace\buildarea\3.x.linaro-win-arm64.nondebug\build\Lib\asyncio\base_events.py", line 745, in call_soonself._check_closed()
^^^^^^^^^^^^^^^^^^^^
File "C:\Workspace\buildarea\3.x.linaro-win-arm64.nondebug\build\Lib\asyncio\base_events.py", line 506, in _check_closedraiseRuntimeError('Event loop is closed')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^RuntimeError: Event loop is closed
k

iritkatriel added a commit that referenced this pull request Jan 23, 2022
iritkatriel added a commit that referenced this pull request Jan 23, 2022
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
@iritkatriel
iritkatriel deleted the bpo-41403 branch December 7, 2022 15:50
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bugAn unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@iritkatriel@miss-islington@bedevere-bot@cjw296@arhadthedev