tox: ImportMismatchError with files under .tox
I’m attempting to convert my projects away from pytest-runner and instead use tox.
In jaraco.mongodb (tox), you can see the tests fail to collect due to repeated ImportMismatchErrors for every module in the package. This happens on every Python version. You can see the failed tests in the Travis Job, but I get the same errors locally when running simply tox.
As you can see in the code, .tox is indicated in norecursedirs.
What can I do next to investigate?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15
Commits related to this issue
- Use usedevelop to workaround tox-dev/tox#373 — committed to jaraco/skeleton by jaraco 8 years ago
- Fix for circleci + virtualenv + pytest + tox (Similar issue here: https://github.com/tox-dev/tox/issues/373#issuecomment-256979815) — committed to schwa/punic by schwa 7 years ago
- jsonpickle: Autospec creation for update from version 1.3 to version 1.4.1 David Aguilar (56): tests: add tests for pandas Series with multi indexes pandas: improve serialization for Seri... — committed to clearlinux-pkgs/jsonpickle by phmccarty 4 years ago
Thanks, James, that’s a very thoughtful consideration and i agree. Without “usedevelop” tox should try to teach/make pytest not collect/import files from the source location. What about tellling pytest to map certain source paths to installed paths? E.g.
--use-installed-py=jaracowould redirect pytest’s collection of the “jaraco” directory to wherever “jaraco” is installed. This would avoid pytest trying to collect from the source path and instead have it collect from the installed path.Or maybe we could make it more automatic by going for an
--collect-prefer-installed-packagegeneric option which, when collecting a python package root (containing an__init__.py) it would check if there is an installed version of the package’s basename and if so, collect from there instead of from source. This last idea might even become a default in some future pytest version (4.0) and would more systematically get rid of the “import mismatch error”. If the reporting clearly indicates this “redirection” and how to disable it, i think it’d be a net win and avoid a problem than many people are puzzled with (newbies and even more senior devs).