I have some python code that normally sends http requests. This code is easy to test because I can record a vcrpy cassette and thereafter I can set record_mode='none'
to ensure that I get the same response every time I run the test.
I am now writing some new code that connects to a stream API and gets data that way instead. I would like to write the same kind of test, where everything is saved in a local file and nothing is sent across the network. This is because I want to ensure that the data recorded during the test is the same every time.
The vcrpy cassette method doesn't work at all, because this code isn't sending http requests. How can I achieve my aim? Is there a different package that works in a similar way?
Sample code:
@pytest.mark.vcr(record_mode='none')
def test_stream():
stream = get_stream()
logger = get_logger()
stream.run_in_thread()
logger.run_in_thread()
time.sleep(10)
stream.stop()
output = read_output_from_logger()
assert output == expected_output
The above test will fail because stream.run_in_thread() actually connects to the streaming API and gets new data every time the test is run.