Skip to content

noah-weingarden/unittest.mock-race-condition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

This repo is a minimal reproducible example of a race condition in unittest.mock. See this GitHub issue.

To demonstrate, run python3 mre.py. You should see output like this every time you run the test:

Test called sendall(), pausing and letting main() continue
main() finished creating sendall() mock, letting test continue
main() sendall() mock: <MagicMock name='socket().__enter__().sendall' id='140244035862144'>
Test resuming call to sendall()
Test sendall() mock: <MagicMock name='socket().__enter__().sendall' id='140244035739248'>
F
======================================================================
FAIL: test_message_sent (__main__.MockTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/noah/unittest-mock-mre/mre.py", line 20, in test_message_sent
    sendall.assert_called()
  File "/home/noah/unittest-mock-mre/mock.py", line 908, in assert_called
    raise AssertionError(msg)
AssertionError: Expected 'sendall' to have been called.

----------------------------------------------------------------------
Ran 1 test in 0.012s

FAILED (failures=1)

About

An MRE for a race condition in Python's unittest.mock

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages