def test_dump_should_persist_state_in_file(): s = State() s.database = 'mongodb' s.pids = [123, 312] state.dump(s) try: with open(state.filename) as fileobj: data = json.load(fileobj) except TypeError: pytest.fail("%r should not be empty" % state.filename) except ValueError: pytest.fail("%r should be JSON" % state.filename) assert {'database': 'mongodb', 'pids': [123, 312]} == data