Some tests do not use conftest.data_dir() to find test data
See original GitHub issueI’m setting up for a test infrastructure that gets the test data from somewhere not near the current working directory of the test. It would be much easier to control this if everything consistently used conftest.data_dir(). test_read_drivers.py
does not. Here is what I ended up with:
import logging
import os
import sys
import conftest
import pytest
import fiona
from fiona.errors import FionaValueError
def test_read_fail():
filepath = os.path.join(conftest.data_dir(), 'coutwildrnp.shp')
with pytest.raises(FionaValueError):
fiona.open(filepath, driver='GeoJSON')
with pytest.raises(FionaValueError):
fiona.open(filepath, enabled_drivers=['GeoJSON'])
def test_read():
filepath = os.path.join(conftest.data_dir(), 'coutwildrnp.shp')
with fiona.open(filepath, driver='ESRI Shapefile') as src:
assert src.driver == 'ESRI Shapefile'
with fiona.open(filepath, enabled_drivers=['GeoJSON', 'ESRI Shapefile']) as src:
assert src.driver == 'ESRI Shapefile'
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
How to teardown in the end of all tests? · Issue #3051 · pytest ...
I tried to create function teardown() in conftest and it is not work. ... Now tests can use that fixture to access the...
Read more >pytest: Is it possible to use pytest-datadir fixtures in Class ...
I want to use pytest-datadir plugin to manage my data files in the ... of the arguments is strict and do not work...
Read more >pytest fixtures: explicit, modular, scalable
Fixtures defined in a conftest.py can be used by any test in that package without needing to import them (pytest will automatically discover...
Read more >Options - Conftest
However, you may find it useful to use as it allows you to compare multiple ... has selector hello-kubernetes that does not match...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree that some consistency would be nice.
The
data_dir
function is actually a pytest fixture, so you can use it as below - you don’t even need toimport conftest
for this to work:@schwehr Would you be willing to make a PR to this effect?
When locally testing, I use
-e
which works all the time, since there’s never multiple copies of things to confuse pytest.On Fedora, we test the installed package, but the installed package is in a temporary buildroot. So
-e
is not really useful since we want to test the install, not some intermediary. Instead,PYTHONPATH
is set to look in the temporary location. Because of the extensions, the problem that we run into is not aboutconftest
, but rather that the sourcefiona
directory comes first in the search path. So as a workaround, I delete the sourcefiona
, which is basically the same as what you do on Travis.So I don’t seem to run into this issue anymore, either because there are never two copies of anything around to confuse pytest, or because of the other fixes that went in between the alpha and the final release.