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

pytest fails collecting on py25 with "import file mismatch" - HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules #223

Closed
pytestbot opened this issue Nov 9, 2012 · 10 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Sorin Sbarnea (BitBucket: sorin, GitHub: sorin)


I use tox + pytest to test my python module but pytest fails to run on python2.5 giving something like:

#!python
import file mismatch:
imported module 'tendo.ansiterm' has this __file__ attribute:
  /Users/sorins/dev/py/tendo/.tox/py25/lib/python2.5/site-packages/tendo/ansiterm.py
which is not the same as the test file we want to collect:
  /Users/sorins/dev/py/tendo/tendo/ansiterm.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

Please take a look at https://github.com/pycontribs/tendo

I am running the tests with the test shell script from the repository root. Everything goes well for python 2.6 and 2.7 but for 2.5 pytest complains about this.

I know that others had similar problems when they included the tests in the libraries but this should be possible, especially for small modules.


@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


i cloned your repo and ran "tox -e py25" and everything worked. Are you maybe using a custom PYTHONPATH or something?

@pytestbot
Copy link
Contributor Author

Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


did a quick test with 2.7 - it failed like described and it looks precisely like the issue is the documented py.test test file discovery and import mechanics

the files imported dont necessaryly fit whats supposed to be on the pythonpath due to workdir vs install site with py.test discovering the tests in the workdir while its actually desired to collect in the install site

i think correct use of py.test --pyargs tendo.tests should fix the perceived problem

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


i'd like to be able to reproduce the problem. Can one of you post the list of commands to do so?

@pytestbot
Copy link
Contributor Author

Original comment by Sorin Sbarnea (BitBucket: sorin, GitHub: sorin):


Ronny, something doesn't work well between tox, py.test. and setup.py - I tried to replace py.test call inside tox.ini with py.test --pyargs tendo.test but now it does collect nothing, the command succeeds but with the cost of running no test.

Here is the final expected behavior: running tox from command line should have almost the same result as running python setup.py test or ./setup.py test.

I just updated the setup.py from tendo so it will run tox when you do setup.py test.

So now something is clear, py.test worked if called directly from setup.py (without tox), but when called by tox it fails.

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


could you retry with recent tox-1.6.1 and pytest-2.3.5 to make sure it's still a problem?

@pytestbot
Copy link
Contributor Author

Original comment by BitBucket: riklaunim, GitHub: riklaunim:


I got it when using pytest-django and after adding an integration test based on django TestCase. The error shows up only when tested via tox.

Solution:
commands=bash -exc "cd {envdir}/lib/python2.7/site-packages && py.test tests"

where "tests" is my tests folder (without that it would test django and everything else discovered.

@pytestbot
Copy link
Contributor Author

Original comment by Anatoly Bubenkov (BitBucket: bubenkoff, GitHub: bubenkoff):


try --recreate for tox
also pass tendo without pyargs, why would you need it?

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


py25 is unsupported as of pytest-2.5.0 and the next tox release so i close this as invalid. It just gets too painful with setuptools, virtualenv and pip not working on py25 anymore.

@pytestbot
Copy link
Contributor Author

Original comment by Michael Aye (BitBucket: michaelaye, GitHub: michaelaye):


I got this problem after I moved tests from proj_name/tests to proj_name/package_name/tests. Suddenly I can't run the tests anymore. Using py2.7 via conda and py.test 2.5.2

@pytestbot
Copy link
Contributor Author

Original comment by Michael Aye (BitBucket: michaelaye, GitHub: michaelaye):


It's ok, I had the old path in pycache. I wasn't ignoring that error message, I just overlooked that the test folder has its own pycache. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant