Running a test module as a script.
I am trying to make my test modules runnable directly as scripts (e.g. python xxx.py) or as a python module (python -m xxx). Everything being done with Python 3.2.rc1 on Windows XP.
The closest I got so far is to add something like this to my test scripts:
if __name__ == "__main__": import pytest pytest.main([__file__])
However, this does not work in all the cases.
Imagine the following scenario (I have attached files modeling this exact scenario so it can be more easily reproduced):
- package module ppp
- test module xxx.py contained inside package ppp
In it I can do the following:
- 'python xxx.py' from the ppp folder
- 'python -m xxx' from the ppp folder
- 'python ppp\xxx.py' from the ppp's parent folder
but trying this:
- 'python -m ppp.xxx' from the ppp's parent folder
causes the following error:
import file mismatch: imported module 'ppp.xxx' has this __file__ attribute: ppp\xxx.py which is not the same as the test file we want to collect: C:\Workplace\ppp\xxx.py HINT: use a unique basename for your test file modules
Is there a better way to do get this functionality or is it something that is not supposed to be supported or is it something that needs fixing?
The error itself is reported from deep inside the py.py library and so far I have not been able to find a quick-fix for it.
Many thanks and best regards, Jurko Gospodnetić