Issue #142 resolved

Executing python file, sys.path is replaced rather than inserted

Anonymous created an issue

In coverage/ the current python module search path sys.argv is replaced rather inserted with the generated module path. This causes problems using coverage in a zc.buildout environment where sys.path is used to point to local installed eggs.

If required to understand the issue, I can try to come up with a patch.

Comments (5)

  1. Ned Batchelder repo owner

    I don't understand the issue: can you explain why your patch works and the original code doesn't? What does zc.buildout do that other code doesn't do? What is the symptom of the problem?

  2. Anonymous

    I have no idea about zc.buildout but this patch fixes a practical issue when running unittest and coverage.

    Before the patch:

    $ python -m unittest my.module
    Ran 5 tests in 0.001s
    $ python -m coverage run -m unittest my.module warning: No data was collected.
    Traceback (most recent call last):
      File "/usr/lib64/python2.7/unittest/", line 12, in <module>
      File "/usr/lib64/python2.7/unittest/", line 94, in __init__
      File "/usr/lib64/python2.7/unittest/", line 149, in parseArgs
      File "/usr/lib64/python2.7/unittest/", line 158, in createTests
      File "/usr/lib64/python2.7/unittest/", line 128, in loadTestsFromNames
        suites = [self.loadTestsFromName(name, module) for name in names]
      File "/usr/lib64/python2.7/unittest/", line 91, in loadTestsFromName
        module = __import__('.'.join(parts_copy))
    ImportError: No module named my

    After the patch:

    $ python -m coverage run -m unittest my.module
    Ran 5 tests in 0.001s

    Previously I had to add '.' to PYTHONPATH in order to get unittest and coverage to cooperate.

    $ env PYTHONPATH=. python -m coverage run -m unittest my.module
    Ran 5 tests in 0.001s
  3. Log in to comment