I'm quite new to pytest and creating packages (modules) in general. I had a few tests written in pytest which worked well until I refactored scripts structure. This was actually neccessary, because there was many scripts and it was quite chaotic for orientation. The current directory structure looks this way:
C:\Users\local\workspace
.+---tools
+---base
+---__init__.py
+---conftest.py
+---script1.py
+---script2.py
+---misc
+---__init__.py
+---run.py
+---__init__.py
script1.py
and script2.py
include some classes and special classes for testing. I was told that conftest.py
should be located in the same folder as top-level test files, so I put it into base
directory.
I run pytest from run.py
by the following way:
pytest_args = workspace + "/tools/base/script1.py "
pytest_args += workspace + "/tools/base/script2.py"
pytest.main(pytest_args)
where workspace
contains c:/Users/local/workspace
. I get this error:
Traceback (most recent call last):
File "c:\Python27\Lib\_pytest\config.py", line 543, in importconftest
mod = conftestpath.pyimport()
File "c:\Python27\Lib\py\_path\local.py", line 660, in pyimport
raise self.ImportMismatchError(modname, modfile, self)
ImportMismatchError: ('tools.base.conftest', 'c:/Users/local/workspace\\jenkins\\tools\\base\\conftest.py', local('c:\\Users\\wokspace\\tools\\base\\conftest.py'))
ERROR: could not load c:\Users\local\workspace\tools\base\conftest.py
I really don't know, how to fix this. Everything worked fine when all scripts were in the same folder (and without __init__.py
). Other scripts work fine (I mean with depencies, where some script needs a module from other directory), just pytest fails on this.
Weird is that on Linux distributions, this works fine. I guess there is a problem with windows paths, which seems to be a real problem for pytest. Do you have any ideas how to solve this please?
Thank you
I ran into a similar problem, and what eventually fixed it was deleting all my __pycache__
directories and .pyc
files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With