question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some tests do not use conftest.data_dir() to find test data

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
snorfalorpaguscommented, Aug 6, 2018

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 to import conftest for this to work:

def test_read_fail(data_dir):
    filepath = os.path.join(data_dir, 'coutwildrnp.shp')
    with pytest.raises(FionaValueError):
        fiona.open(filepath, driver='GeoJSON')
    with pytest.raises(FionaValueError):
        fiona.open(filepath, enabled_drivers=['GeoJSON'])

@schwehr Would you be willing to make a PR to this effect?

0reactions
QuLogiccommented, Nov 29, 2018

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 about conftest, but rather that the source fiona directory comes first in the search path. So as a workaround, I delete the source fiona, 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.

Read more comments on GitHub >

github_iconTop 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 >
pytest_cleanup - PyPI
Automated, comprehensive and well-organised pytest test cases.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found