coverage.py can't find source file

R

Richard Wesley

I am using coverage.py to run my unit test suite to check for missing
tests. It mostly works, but for some mysterious reason, some of the
files can't be found because they are not in the same directory as
configure.py and unit_test.py. But only SOME of them.

Anyone have any ideas?
 
P

Peter Hansen

Richard said:
I am using coverage.py to run my unit test suite to check for missing
tests. It mostly works, but for some mysterious reason, some of the
files can't be found because they are not in the same directory as
configure.py and unit_test.py. But only SOME of them.

Anyone have any ideas?

Yes, but probably not the right one. :) Anyway, is it possible
that actually *none* of those files are being found, but instead
a bunch of leftover .pyc files in the current directory (or any
other directory that Python can find) are being found? .pyc files
are as good as .py files to Python, if it can't find the latter.

Also, are you aware of how sys.path is used? If you check each
directory, starting with the directory in which the main script
is found (and which shows up as '' in sys.path, usually at the start)
for the files, you should be able to find them. You can also
try importing one of the files that works, then do 'print module.__file__'
where module is replaced by the right name, and see where the
files that do work are actually coming from. It might not be
where you think it is.

Finally, try learning how to use "import pdb; pdb.set_trace()"
which starts an interactive debugger session in the context where
it executes. Putting this just ahead of the failing imports
would let you interactively debug the problem.

-Peter
 
J

John Roth

Richard Wesley said:
I am using coverage.py to run my unit test suite to check for missing
tests. It mostly works, but for some mysterious reason, some of the
files can't be found because they are not in the same directory as
configure.py and unit_test.py. But only SOME of them.

Anyone have any ideas?

Where is coverage.py from? I used pycover at one point (found it
on the Vaults of Parnassus) and had to improve it for a number
of reasons.

John Roth
 
F

Follower

some of the files can't be found because they are not in the same directory as
configure.py and unit_test.py. But only SOME of them.
I believe there is a known issue with utilities that make use of .pyc
files (such as coverage tools) relating to the use of non-absolute
file paths.

The file path that gets stored as the "__file__" attribute is a
relative path, as a result, if an attempt is made to locate the source
file it will fail if the current directory is different to the current
directory when the .pyc file was created.

--Phil.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top