pytest: FileNotFoundError: [Errno 2] only when running individual tests

i've configured pytest to work in pycharm. i am able to run / debug tests OK. 

 

the only issue is when i try to re-run a specific test. my tests load sample .csv with test data, and that fails in this case

/anaconda3/envs/consent/lib/python3.7/site-packages/pandas/io/parsers.py:1906: in __init__
self._reader = parsers.TextReader(src, **kwds)
pandas/_libs/parsers.pyx:380: in pandas._libs.parsers.TextReader.__cinit__
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

> ???
E FileNotFoundError: [Errno 2] File b'src/tests/fixtures/my-data.csv' does not exist: b'src/tests/fixtures/my-data.csv'

pandas/_libs/parsers.pyx:687: FileNotFoundError

the path src/tests/fixtures/my-data.csv is correct. so most likely running individual tests uses a different starting point? 


i need to run the individual test in the same way as running all of them, with src/ as my root working dir 

 

1 comment
Comment actions Permalink

Hi,

I could not reproduce the issue, so let's do some testing:

1. Please add print of your current working directory into your test and reproduce the issue. What does it print? 

e.g.

import os; print("\n\nCurrent workdir is: " + os.getcwd() + "\n\n")

2. Is it consistent with pytest run/debug configuration that is being generated when you run the individual test?

3. Check pytest run/debug configuration template, maybe you set a working directory there.

0

Please sign in to leave a comment.