Skip to content
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

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

Closed
nedbat opened this issue Jul 26, 2011 · 4 comments
Closed

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

nedbat opened this issue Jul 26, 2011 · 4 comments
Labels
bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Jul 26, 2011

Originally reported by Anonymous


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.


@nedbat
Copy link
Owner Author

nedbat commented Jul 26, 2011

Original comment by Daniele Nicolodi (Bitbucket: daniele, GitHub: daniele)


Something like this may work (untested)

@nedbat
Copy link
Owner Author

nedbat commented Oct 30, 2011

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?

@nedbat
Copy link
Owner Author

nedbat commented Mar 29, 2012

Original comment by 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

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

@nedbat
Copy link
Owner Author

nedbat commented Apr 22, 2013

This was fixed in October of 2011, in changeset 781082764b17 (bb).

@nedbat nedbat closed this as completed Apr 22, 2013
@nedbat nedbat added major bug Something isn't working labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant