I am new to pytest and creating packages (modules) in general. I had several tests written in pytest that worked well until I redesigned the script structure. It was really necessary because there were many scenarios, and it was pretty chaotic for orientation. The current directory structure is as follows:
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 in the same folder as the top-level test files, so I put it in the base directory.
I run pytest from run.py as follows:
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 the scripts were in the same folder (and without __init__.py ). Other scripts work fine (I mean with dependencies where some scripts need a module from another directory), just pytest fails.
The strange thing is that on Linux distributions this works great. I think there is a problem with window paths, which seems to be the real problem for pytest. Do you have any idea how to solve this?
thanks
source share