Skip to content

Test fixture datapath uses relative instead of absoulte file paths #21646

Closed
@elmq0022

Description

@elmq0022

The following code in pandas/blob/master/pandas/conftest.py uses a relative vs absolute path.

@pytest.fixture
def datapath(request):
    """Get the path to a data file.
    Parameters
    ----------
    path : str
        Path to the file, relative to ``pandas/tests/``
    Returns
    -------
    path : path including ``pandas/tests``.
    Raises
    ------
    ValueError
        If the path doesn't exist and the --strict-data-files option is set.
    """
    def deco(*args):
        path = os.path.join('pandas', 'tests', *args)
        if not os.path.exists(path):
            if request.config.getoption("--strict-data-files"):
                msg = "Could not find file {} and --strict-data-files is set."
                raise ValueError(msg.format(path))
            else:
                msg = "Could not find {}."
                pytest.skip(msg.format(path))
        return path
    return deco

This means that the test runner must be run from the root of the project directory which could be inconvenient when running tests in a specific directory.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: 36422a8 python: 3.6.5.final.0 python-bits: 64 OS: Linux OS-release: 4.15.0-23-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.24.0.dev0+170.g36422a884
pytest: 3.6.2
pip: 10.0.1
setuptools: 39.2.0
Cython: 0.28.3
numpy: 1.14.5
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: 1.7.5
patsy: None
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions