Skip to content

Instantly share code, notes, and snippets.

@Eitol
Created April 13, 2018 02:34
Show Gist options
  • Save Eitol/abc5c515a6b58bf55ee5143e85b612eb to your computer and use it in GitHub Desktop.
Save Eitol/abc5c515a6b58bf55ee5143e85b612eb to your computer and use it in GitHub Desktop.
mock pytest parametrize test
# 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