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

Stub out os.stat raises exception when run with pytest #32

Open
ivancrneto opened this issue Jan 6, 2024 · 0 comments
Open

Stub out os.stat raises exception when run with pytest #32

ivancrneto opened this issue Jan 6, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ivancrneto
Copy link
Owner

  1. Create a minimum testcase
import mox
import os

class TestExample:
    def test_stat(self):
        mock = mox.Mox()
        mock.stubout(os, 'stat')
        stat = mock.create_mock_anything()
        os.stat('a').returns(stat)

        mock.replay_all()
        print(os.stat('a'))
        mock.verify_all()
        mock.unset_stubs()
  1. pytest
  2. Exception is raised because pytest is using os.stat, which is stubbed out
  File "/home/user/.pyenv/versions/3.12.1/lib/python3.12/pathlib.py", line 840, in stat
    return os.stat(self, follow_symlinks=follow_symlinks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/projects/pymox/mox/mox.py", line 851, in __call__
    return mock_method(*params, **named_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/projects/pymox/mox/mox.py", line 1159, in __call__
    expected_method = self._verify_method_call()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/projects/pymox/mox/mox.py", line 1209, in _verify_method_call
    expected = self._pop_next_method()
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/projects/pymox/mox/mox.py", line 1195, in _pop_next_method
    raise exception
mox.exceptions.UnexpectedMethodCallError: Unexpected method call builtin_function_or_method.__call__(PosixPath('...'), follow_symlinks=True) -> None
@ivancrneto ivancrneto added the bug Something isn't working label Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant