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

Issue #142 resolved
Former user created an issue

In coverage/execfile.py 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. Former user Account Deleted

    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
    
    OK
    
    $ python -m coverage run -m unittest my.module
    Coverage.py warning: No data was collected.
    Traceback (most recent call last):
      File "/usr/lib64/python2.7/unittest/__main__.py", line 12, in <module>
        main(module=None)
      File "/usr/lib64/python2.7/unittest/main.py", line 94, in __init__
        self.parseArgs(argv)
      File "/usr/lib64/python2.7/unittest/main.py", line 149, in parseArgs
        self.createTests()
      File "/usr/lib64/python2.7/unittest/main.py", line 158, in createTests
        self.module)
      File "/usr/lib64/python2.7/unittest/loader.py", line 128, in loadTestsFromNames
        suites = [self.loadTestsFromName(name, module) for name in names]
      File "/usr/lib64/python2.7/unittest/loader.py", 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
    
    OK
    

    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
    
    OK
    
  3. Log in to comment