Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird interaction with pytest-mock: not requesting event_loop fixture leads to errors #818

Open
twisteroidambassador opened this issue Apr 19, 2024 · 0 comments
Labels
Milestone

Comments

@twisteroidambassador
Copy link

Consider the two test cases below:

@pytest.mark.asyncio
async def test_mocksocket_mocker(mocker):
    mocker.patch('socket.socket', wraps=MockSocket)
    pass


@pytest.mark.asyncio
async def test_mocksocket_loop_mocker(event_loop, mocker):
    mocker.patch('socket.socket', wraps=MockSocket)
    pass

The top one reports ERROR at teardown of test_mocksocket_mocker. The bottom one does not report any error. The only difference between them is that the bottom one requests the event_loop fixture.

The error message is quite long. It seems to be caused by MockSocket still being active when _provide_clean_event_loop() is called, and the new event loop failing at initialization.

Also, if the test case calls unittest.mock.patch instead of mocker.patch, then there is no error.

Attached is the test file, full console output, and package versions. This is running on Windows 10.

pytest-asyncio-mock.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants