Skip to content

Instantly share code, notes, and snippets.

@edsu
Last active May 10, 2023 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edsu/d0914e120f8eaf80ad8129df405c24a5 to your computer and use it in GitHub Desktop.
Save edsu/d0914e120f8eaf80ad8129df405c24a5 to your computer and use it in GitHub Desktop.
class Example:
def __init__(self):
self.var = 1
def run(self):
return self.var
pytest
pytest-mock
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