Issue 8547: unittest test discovery can fail when package under test is also installed globally (original) (raw)
This issue has been migrated to GitHub: https://github.com/python/cpython/issues/52793
classification
Title: | unittest test discovery can fail when package under test is also installed globally | ||
---|---|---|---|
Type: | behavior | Stage: | resolved |
Components: | Library (Lib) | Versions: | Python 3.2, Python 2.7 |
process
Status: | closed | Resolution: | accepted |
---|---|---|---|
Dependencies: | Superseder: | ||
Assigned To: | michael.foord | Nosy List: | benjamin.peterson, hpk, michael.foord |
Priority: | normal | Keywords: |
Created on 2010-04-27 12:23 by michael.foord, last changed 2022-04-11 14:57 by admin. This issue is now closed.
Messages (6) | ||
---|---|---|
msg104313 - (view) | Author: Michael Foord (michael.foord) * ![]() |
Date: 2010-04-27 12:23 |
When test discovery is invoked on a package on the filesystem which is also installed in site-packages then importing the tests will look in the installed version. This causes discovery to run the wrong tests or fail. We can detect this (compare the __file__ against the expected location) and also insert the top level path as the first location in sys.path instead of appending it to the end. If we detect a failed import then we should error out with an appropriate message. (Nose gets round this by patching __import__ to import from a specific location which seems potentially fragile.) | ||
msg104659 - (view) | Author: holger krekel (hpk) | Date: 2010-04-30 19:32 |
FWIW checking if an imported module really comes from a certain location and erroring out is also how py.test does it. | ||
msg104660 - (view) | Author: Michael Foord (michael.foord) * ![]() |
Date: 2010-04-30 19:33 |
Sounds like the right approach then. :-) | ||
msg105220 - (view) | Author: Michael Foord (michael.foord) * ![]() |
Date: 2010-05-07 18:16 |
Committed revision 80932. Still needs documenting, so leaving open for the moment. | ||
msg105226 - (view) | Author: Benjamin Peterson (benjamin.peterson) * ![]() |
Date: 2010-05-07 20:46 |
Reverted this in r80939. See http://python.org/dev/buildbot/stable/builders/x86%20XP-4%20trunk/builds/3553/steps/test/logs/stdio | ||
msg105246 - (view) | Author: Michael Foord (michael.foord) * ![]() |
Date: 2010-05-07 23:46 |
Committed again revision 80946 after getting the tests to pass on Windows. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:57:00 | admin | set | github: 52793 |
2010-05-08 18:08:10 | michael.foord | set | status: open -> closedresolution: acceptedstage: needs patch -> resolved |
2010-05-07 23:46:14 | michael.foord | set | messages: + |
2010-05-07 20:46:23 | benjamin.peterson | set | nosy: + benjamin.petersonmessages: + |
2010-05-07 18:16:47 | michael.foord | set | messages: + |
2010-04-30 19:33:52 | michael.foord | set | messages: + |
2010-04-30 19:32:15 | hpk | set | nosy: + hpkmessages: + |
2010-04-27 12:23:17 | michael.foord | create |