Last active
January 19, 2021 17:02
-
-
Save poros/c9781ebe6367c7dec593 to your computer and use it in GitHub Desktop.
Compose pytest fixtures at the same level and mock.patch
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
@pytest.fixture | |
def stream(): | |
return mock.Mock(spec=Stream) | |
@pytest.fixture | |
def output(): | |
return open('test.txt', 'w') | |
@pytest.fixture | |
def tailer(self, stream, output): | |
with mock.patch('logging.getLogger', autospec=True): | |
yield Tailer(stream, output, mock.sentinel.lines) | |
@mock.patch('consumer.read_lines', autospec=True) | |
def test_tailer(mock_read, tailer, stream): | |
stream.fetch.return_value = "test\n" | |
tailer.run() | |
mock_read.assert_called_once_with(stream, mock.sentinel.lines) | |
with open('test.txt', 'r') as f: | |
assert f.read() == "test" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment