-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
"import file mismatch" with git #774
Comments
Are you reusing a previous working copy from Mercurial perhaps? I just tried with a fresh clone and |
uhm, no. I don't mean the pytest source code. I mean my tests/ folder which is in a git repository. |
|
Sorry, I thought this was related to our recent move from Hg to Git. Can you post the full error message? There might be a clue in there. |
find → doesn't find any line.
|
The problem is that your test files are within the package source and have the same name, as the |
They aren't. |
Sorry, you're correct. Do your |
Yes, they do. I deleted them now. I will see if the error persists then. |
Hm, is still occurs after the removal of all $(find tests/ -name init.py -delete) |
btw. the file is empty.
|
I can reproduce this with test files outside of the package (without It can also be reproduced with this simple structure (with empty files):
It sounds like the "files need unique basenames" thing is just a pytest limitation rather than an actual bug? |
oh, yes it is that simple to reproduce :D |
Yes, it is a known documented limitation. Insert |
This is required for my particular use case -- running pytest on the generated code directory -- due to <pytest-dev/pytest#774>. It ought to be abstracted out, especially if we ever support non-python code blocks.
Had the same issue.. and adding empty
Did not help. What about: |
We can't use relative imports any more since the tests are now located outside the package. I had to add __init__.py to Tests/feaLib/ so that pytest does not get confused by the presence of two test files with the same basename: i.e. Tests/feaLib/builder_test.py and Tests/feaLib/builder_test.py pytest-dev/pytest#774 http://stackoverflow.com/questions/12582503/py-test-test-discovery-failure-when-tests-in-different-directories-are-called
We can't use relative imports any more since the tests are now located outside the package. I had to add __init__.py to Tests/feaLib/ so that pytest does not get confused by the presence of two test files with the same basename: i.e. Tests/feaLib/builder_test.py and Tests/feaLib/builder_test.py pytest-dev/pytest#774 http://stackoverflow.com/questions/12582503/py-test-test-discovery-failure-when-tests-in-different-directories-are-called
define an empty pytest.ini file in project tree, or add inside it :
|
Py.test apparently has some weird behavior with test files that have the same names in different directories: pytest-dev/pytest#774 Adding empty `__init__.py` files in those directories seems to fix the problem.
Py.test apparently has some weird behavior with test files that have the same names in different directories: pytest-dev/pytest#774 Adding empty `__init__.py` files in those directories seems to fix the problem.
Py.test apparently has some weird behavior with test files that have the same names in different directories: pytest-dev/pytest#774 Adding empty `__init__.py` files in those directories seems to fix the problem.
Py.test apparently has some weird behavior with test files that have the same names in different directories: pytest-dev/pytest#774 Adding empty `__init__.py` files in those directories seems to fix the problem.
I hit this because I had a directory structure that looked like this:
I was deleting |
These tests did not exist so we add them first before making changes. Add the __init__.py file to make test imports work properly. ie. To solve pytest-dev/pytest#774 More useful info on how that works here: https://docs.pytest.org/en/latest/goodpractices.html#choosing-a-test-layout-import-rules
In my case, I had to delete the directory in the line:
module_file was using the |
I often get errors saying "import file mismatch" and a suggestion to remove pycache / *.pyc.
I removed all these files but the message still occurs.
I can think of git being the reason for it because it marks some files as "moved" internally. I don't know what is the underlying magic there.
The text was updated successfully, but these errors were encountered: