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

Partially missed error description with running via Pytest #10572

Open
david-shiko opened this issue Dec 10, 2022 · 0 comments
Open

Partially missed error description with running via Pytest #10572

david-shiko opened this issue Dec 10, 2022 · 0 comments
Labels
topic: reporting related to terminal output and user-facing messages and errors

Comments

@david-shiko
Copy link

david-shiko commented Dec 10, 2022

Missed the important part of error description during running via Pytest.

Please compare this 2 outputs of pytest running and python running.
It's really blowmind :)

MVE:

(venv) david@david-ThinkPad-E480:~/PycharmProjects$ cat tests/delme.py
# Put this code inside your "conftest.py" file
from unittest.mock import Mock
class F:
    def x(self):
        pass
m = Mock()
m.x = Mock(spec_set=F.x)  # Antipattern! Use just "return_value"
m.x()
m.x.assert_called_once_with()

Pytest output:

(venv) david@david-ThinkPad-E480:~/PycharmProjects$ python3.10 -m pytest tests/delme.py 
ImportError while loading conftest '/home/david/PycharmProjects/tests/conftest.py'.
tests/conftest.py:1292: in <module>
    m.x.assert_called_once_with()
/usr/lib/python3.10/unittest/mock.py:941: in assert_called_once_with
    return self.assert_called_with(*args, **kwargs)
/usr/lib/python3.10/unittest/mock.py:929: in assert_called_with
    raise AssertionError(_error_message()) from cause
E   AssertionError: expected call not found.
E   Expected: x()  # WTF?
E   Actual: x()  # WTF?

Python output (missed important part of error):

(venv) david@david-ThinkPad-E480:~/PycharmProjects$ python3.10 tests/delme.py 
TypeError: missing a required argument: 'self'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/david/PycharmProjects/tests/delme.py", line 8, in <module>
    m.x.assert_called_once_with()
  File "/usr/lib/python3.10/unittest/mock.py", line 941, in assert_called_once_with
    return self.assert_called_with(*args, **kwargs)
  File "/usr/lib/python3.10/unittest/mock.py", line 929, in assert_called_with
    raise AssertionError(_error_message()) from cause
AssertionError: expected call not found.
Expected: x()  # The real reason above
Actual: x()  # The real reason above
(venv) david@david-ThinkPad-E480:~/PycharmProjects$ pip list | grep pytest
pytest                7.1.3
(venv) david@david-ThinkPad-E480:~/PycharmProjects$ uname -a
Linux david-ThinkPad-E480 5.15.0-56-generic #62~20.04.1-Ubuntu SMP Tue Nov 22 21:24:20 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
@Zac-HD Zac-HD added the topic: reporting related to terminal output and user-facing messages and errors label Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: reporting related to terminal output and user-facing messages and errors
Projects
None yet
Development

No branches or pull requests

2 participants