Jul-31-2018, 10:41 AM
While Testing a
When the fixture is included in the test file -
If I add the fixture
But now if I run
@pytest.fixture(scope="module")When the fixture is included in the test file -
tests/test_authors.py, test works fineimport json, pytest
@pytest.fixture(scope='module')
def author_file_json(tmpdir_factory):
python_author_data = {
'Ned': {'City': 'Boston'},
'Brian': {'City': 'Portland'},
'Luciano': {'City': 'Sau Paulo'}
}
file = tmpdir_factory.mktemp('data').join('author_file.json')
print('file:{}'.format(str(file)))
with file.open('w') as f:
json.dump(python_author_data, f)
return file
def test_brian_in_portland(author_file_json):
with author_file_json.open() as f:
authors = json.load(f)
assert authors['Brian']['City'] == 'Portland' If I add the fixture
author_file_json to conftest.py and run pytest --fixtures, it shows up in the trace But now if I run
pytest tests/test_authors.py, I get an error - Error:E fixture 'author_file_json' not foundHow can I fix this ?
