Repository: pandas-dev/pandas

Issue:
Test fixture datapath uses relative instead of absoulte file paths
The following code in pandas/blob/master/pandas/conftest.py uses a relative vs absolute path.  

```python
@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()``

<details>
INSTALLED VERSIONS
------------------
commit: 36422a88474396148bd7d5d38aa238ea844d9555
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
</details>


Discussion:

Resolving patch:
diff --git a/pandas/conftest.py b/pandas/conftest.py
--- a/pandas/conftest.py
+++ b/pandas/conftest.py
@@ -153,8 +153,10 @@ def datapath(request):
     ValueError
         If the path doesn't exist and the --strict-data-files option is set.
     """
+    BASE_PATH = os.path.join(os.path.dirname(__file__), 'tests')
+
     def deco(*args):
-        path = os.path.join('pandas', 'tests', *args)
+        path = os.path.join(BASE_PATH, *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."


Test patch:
diff --git a/pandas/tests/util/test_testing.py b/pandas/tests/util/test_testing.py
--- a/pandas/tests/util/test_testing.py
+++ b/pandas/tests/util/test_testing.py
@@ -852,5 +852,10 @@ def test_datapath_missing(datapath, request):
         datapath('not_a_file')
 
     result = datapath('data', 'iris.csv')
-    expected = os.path.join('pandas', 'tests', 'data', 'iris.csv')
+    expected = os.path.join(
+        os.path.dirname(os.path.dirname(__file__)),
+        'data',
+        'iris.csv'
+    )
+
     assert result == expected