diff --git a/pandas/conftest.py b/pandas/conftest.py index 5aa644bb942f8..f383fb32810e7 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -275,7 +275,12 @@ def join_type(request): @pytest.fixture -def datapath(request): +def strict_data_files(pytestconfig): + return pytestconfig.getoption("--strict-data-files") + + +@pytest.fixture +def datapath(strict_data_files): """Get the path to a data file. Parameters @@ -297,7 +302,7 @@ def datapath(request): def deco(*args): path = os.path.join(BASE_PATH, *args) if not os.path.exists(path): - if request.config.getoption("--strict-data-files"): + if strict_data_files: msg = "Could not find file {} and --strict-data-files is set." raise ValueError(msg.format(path)) else: diff --git a/pandas/tests/util/test_util.py b/pandas/tests/util/test_util.py index a2dc9b699566a..e40784fd5467c 100644 --- a/pandas/tests/util/test_util.py +++ b/pandas/tests/util/test_util.py @@ -100,13 +100,13 @@ def test_assert_raises_regex_deprecated(): assert 1 == 2, msg -def test_datapath_missing(datapath, request): - if not request.config.getoption("--strict-data-files"): - pytest.skip("Need to set '--strict-data-files'") - +@pytest.mark.parametrize('strict_data_files', [True, False]) +def test_datapath_missing(datapath): with pytest.raises(ValueError, match="Could not find file"): datapath("not_a_file") + +def test_datapath(datapath): args = ("data", "iris.csv") result = datapath(*args)