-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
pytest.main function gives an error when tested module is in the PYTHONPATH #3128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you show the full output you get? |
The output I get is only the default header of pytest, and then the error I wrote: |
without accurate information we are unable to determine whats actually up |
Could you tell me the exact info you need? |
folder structure, exact invocations and the exact output |
The exact output: (I forgot to mention that I work with python 2.7)
The exact invocation: import pytest
result = pytest.main(args=['path_to_test_file', '-v', '-s'])
if not result:
sys.exit(1) Folder Structure:
PYTHONPATH = /home/My_Project/outputs Therefore, |
For zip files to work you need to add the path to the zip file in the PYTHONPATH, not the path to the directory that contains the zip file. IOW, your PYTHONPATH should contain Furthermore, for pytest to be able to import those tests files you will need the |
Hi, Sorry it took so much time to report back about the try. |
Hi @jlevertov, I managed to reproduce your issue I think: I created two zip files (although only one should be sufficient), then I added the full path to them to
This happens regardless if I use Looking at the code which handles Lines 793 to 808 in 3bc7ced
This would require some support in |
This is a duplicate of #1445 |
In my case the tests do run for os.system command and when using pytest.main I get a totally different error than what you got:
The packages do have init.py in them, and are found when needed. |
Well I'm on Windows, perhaps it is related to that (although looking at the code I can't really see how). Perhaps you can package a zipfile with all the files required to reproduce your problem? I would be happy to give that a go to see if I can explain the discrepancy between our runs, although pytest doesn't support importing test files from zipfiles at the moment AFAIK. |
Thank you for your help, after further analysis, it appears that something in the project was causing this problem, I did a fresh start and everything appears to be working. |
Hi,
I created a package for configuring how to run tests - it gets user input and translates it to the necessary pytest flags and command format - this package is called "package a".
And I also created another package in which I write the tests - this package is called "package b"
Both of the packages are packaged as zip file, and added to the PYTHONPATH.
The issue is:
When using
pytest.main(args=list of arguments)
, I get the following error:E ENOTDIR: [Not a directory]: samefile('path to requested test file', 'path to requested test file inside the zipped tests package - "package b" ').
On the other hand, when running the command as a bash command:
os.system('python -m pytest ...')
everything works perfectly.
A small code example: The not working way
A small code example: The working way
My specs:
Operating system: Debian 8.1
pytest: 3.3.0 (also tried on version 3.3.2)
py: 1.5.2
six: 1.11.0
setuptools: 38.4.0
attrs: 17.4.0
The text was updated successfully, but these errors were encountered: