[SOLVED] PyCharm can no longer find conftest.py file for running tests, but it exists.

Completed

I've been using PyCharm CE 2019.2.3 to run and debug tests for a library I'm developing. It's been working fine for a while, however it has suddenly stopped working (admittedly, I had to hard reboot my laptop beforehand, I don't know if that has caused it).

The error it comes up with is:

_pytest.config.ConftestImportFailure: (local('/home/theo/Documents/development/ProviderAssetLookup/tests/conftest.py'), (<type 'exceptions.OSError'>, OSError(2, 'No such file or directory'), <traceback object at 0x7f352fbec550>))

 

However the conftest file listed does exist. If I run pytest in a terminal instead, it works fine. If I open a python shell and run os.path.exists and os.path.isfile on the conftest path, it says True. All evidence points to that file existing and being readable/useable by pytest, but for some reason PyCharm can no longer find it.

Any ideas on how I might get this working again?

Thank you.

Full traceback:

Testing started at 13:32 ...
/home/theo/Documents/development/ProviderAssetLookup/venv/bin/python /usr/share/pycharm/helpers/pycharm/_jb_pytest_runner.py --path /home/theo/Documents/development/ProviderAssetLookup/tests/test_video_assets.py
Launching pytest with arguments /home/theo/Documents/development/ProviderAssetLookup/tests/test_video_assets.py in /home/theo/Documents/development/ProviderAssetLookup/tests

Traceback (most recent call last):
File "/usr/share/pycharm/helpers/pycharm/_jb_pytest_runner.py", line 37, in <module>
config_result = real_prepare_config(args, plugins_to_load)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/_pytest/config/__init__.py", line 207, in _prepareconfig
pluginmanager=pluginmanager, args=args
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/pluggy/hooks.py", line 289, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/pluggy/manager.py", line 87, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/pluggy/manager.py", line 81, in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/pluggy/callers.py", line 203, in _multicall
gen.send(outcome)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/_pytest/helpconfig.py", line 94, in pytest_cmdline_parse
config = outcome.get_result()
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/pluggy/callers.py", line 81, in get_result
_reraise(*ex) # noqa
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/_pytest/config/__init__.py", line 687, in pytest_cmdline_parse
self.parse(args)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/_pytest/config/__init__.py", line 895, in parse
self._preparse(args, addopts=addopts)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/_pytest/config/__init__.py", line 851, in _preparse
early_config=self, args=args, parser=self._parser
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/pluggy/hooks.py", line 289, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/pluggy/manager.py", line 87, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/pluggy/manager.py", line 81, in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/pluggy/callers.py", line 208, in _multicall
return outcome.get_result()
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/pluggy/callers.py", line 81, in get_result
_reraise(*ex) # noqa
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/_pytest/config/__init__.py", line 750, in pytest_load_initial_conftests
self.pluginmanager._set_initial_conftests(early_config.known_args_namespace)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/_pytest/config/__init__.py", line 383, in _set_initial_conftests
self._try_load_conftest(anchor)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/_pytest/config/__init__.py", line 389, in _try_load_conftest
self._getconftestmodules(anchor)
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/_pytest/config/__init__.py", line 424, in _getconftestmodules
mod = self._importconftest(conftestpath.realpath())
File "/home/theo/Documents/development/ProviderAssetLookup/venv/lib/python2.7/site-packages/_pytest/config/__init__.py", line 463, in _importconftest
raise ConftestImportFailure(conftestpath, sys.exc_info())
_pytest.config.ConftestImportFailure: (local('/home/theo/Documents/development/ProviderAssetLookup/tests/conftest.py'), (<type 'exceptions.OSError'>, OSError(2, 'No such file or directory'), <traceback object at 0x7f352fbec550>))

Process finished with exit code 1

Empty suite

Empty suite

0
9 comments

I'm bumping this thread because the problem has continued to crop up and deleting configuration files no longer helps. Does anyone have any ideas why this could be happening? It's driving me crazy not being able to debug my tests.

0

Hi,

Does it happen with all of your tests?

Is it reproducible in a new project with a single test file, for instance?

0

Yes it happens with any test I run.

I started a new project with a new interpreter, a conftest with one fixture and a single test in a separate file. The test seems to run fine.

I tried setting the interpreter to the one I am using for my main project and it also ran the test fine then too.

0

So it's a project-specific issue.

>but suspect it was the .idea directory causing problems.

Is it why you think so? Have you tried temporarily removing .idea folder?

0

Removing .idea previously would help temporarily, but the problem would reoccur after a short while.

If I remove .idea now, it doesn't seem to help with the problem.

I've realised the part you're quoting was part of my edit. I meant to remove it once I reopened this thread. I've taken it out now as that solution no longer works.

0

Does the issue reproduce in the 2019.3 version?

>If I run pytest in a terminal instead, it works fine. 

Was it your system terminal or PyCharm's terminal?

0

I think I've narrowed down the problem.

I updated to 2019.3 (Community EAP version) and it gave me a much clearer error message. My conftest uses subprocess to open azurite (a mock server that runs in the background).

For some reason it isn't able to find azurite in path. Probably because I have my zshrc to add a node bin directory in my home to path, but pycharm isn't making use of that. That explains why it works in my terminal but not in pycharm.

The error message given in 2019.2 implies it can't find the conftest file, but now I realise it's saying "error importing conftest, this is the exception that occurred during import":

_pytest.config.ConftestImportFailure: (local('/home/theo/Documents/development/SMT/CloudProviders/tests/conftest.py'), (<type 'exceptions.OSError'>, OSError(2, 'No such file or directory'), <traceback object at 0x7f1a6994a370>))

I guess they've made this clearer in the next version.

I can't explain why it would sometimes work and sometimes not though. Is there any way I can configure pycharm to make use of my user's $PATH? I can put the full path in but I'd like it to work on other systems without having to change the username if possible (the full path is in my home).

Thanks Sergey for the help so far.

0

So you specify it through some env variable?
Does it help if you add that variable to run configuration in PyCharm?

If it's not loaded indeed, then starting PyCharm from the system terminal is mosy likely gonna help.

0

That helps. I've added it to Environment variables in Templates > Python tests > pytest and all is working well.

You're right if I start Pycharm from the terminal it works, but not if I run it from my desktop launcher. I must have been doing that sometimes before and sometimes not.

Thank you Sergey. This is solved.

0

Please sign in to leave a comment.