Last active
May 10, 2023 13:59
-
-
Save edsu/d0914e120f8eaf80ad8129df405c24a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Example: | |
def __init__(self): | |
self.var = 1 | |
def run(self): | |
return self.var |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pytest | |
pytest-mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
from example import Example | |
def test_run(): | |
e = Example() | |
assert e.run() == 1 | |
@pytest.fixture | |
def mock_example(mocker): | |
m = mocker.patch('example.Example.run') | |
m.return_value = 2 | |
def test_run_mocked(mock_example): | |
e = Example() | |
assert e.run() == 2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment