Created
April 13, 2018 02:34
-
-
Save Eitol/abc5c515a6b58bf55ee5143e85b612eb to your computer and use it in GitHub Desktop.
mock pytest parametrize test
This file contains hidden or 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
# first install pip3 install pytest-mock | |
import os | |
import pytest | |
class TestNodeInteractor: | |
def exists(self, path): | |
return os.path.exists(path) | |
@pytest.fixture(autouse=True) | |
def mock_exists(self, mocker, expect): | |
mocker.patch('os.path.exists', return_value=expect) | |
@pytest.mark.parametrize( | |
"path, expect", | |
[('foo', True), ('bar', False)], | |
) | |
def test_exists(self, path, expect): | |
assert self.exists(path) == expect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment