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

"import file mismatch" despite different names (only Windows 7?) #702

Closed
pytestbot opened this issue Mar 19, 2015 · 17 comments
Closed

"import file mismatch" despite different names (only Windows 7?) #702

pytestbot opened this issue Mar 19, 2015 · 17 comments
Labels
platform: windows windows platform-specific problem type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: BitBucket: punch_card, GitHub: punch_card


I have published a full description of the problem at StackOverflow, but here follows a terse summary.

I have tried to device a simple set of black box tests, following the directory structure and naming recommendations. When I try to run all tests from the top of the structure, I consistently get error messages of this kind:

ERROR collecting /prgm_A/test/test_A.py
import file mismatch:
imported module 'test_A' has this file attribute:
X:\prgm_A\test\test_A.py
which is not the same as the test file we want to collect:
X:\prgm_A\test\test_A.py
HINT: remove pycache / ...

My workaround, to step down into the individual test directories for each subprogram and run the subsets of tests from there, stopped working when our computers were migrated to 7.

I don't see this happen under linux.

Note that the page at StackOverflow includes a minimal code example which reproduces this problem.


@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
@RonnyPfannschmidt
Copy link
Member

@punch_card this is not a bug, as far as i can tell the python module name is the same for both test modules

py.test complains about different files ending up with the same module name, thus breaking details

can you verify?

@RonnyPfannschmidt
Copy link
Member

@nicoddemus some bb<>gh name mappings are incorrect, how can we elevate that

@The-Compiler
Copy link
Member

@RonnyPfannschmidt I wonder if it's really something which needs fixing - it might be difficult to do so.

@RonnyPfannschmidt
Copy link
Member

@The-Compiler we should have some better error reporting, its not something we can fix tho

@The-Compiler
Copy link
Member

Sorry - I was talking about the wrong name issue, not this issue 😉

@punch-card
Copy link

Hi RonnyPfannschmidt and others,

Well, actually it is a bug, but a small mishap has occurred in the communications. The two paths reported in the error message are different. The second mention of X:\prgm_A\test\test_A.py should have one extra backslash after the X:, but this was swallowed by the BitBucket markup language interpreter. The full and correct description of the problem is still available at StackOverflow.

(The reason I am suddenly "punch-card" instead of "punch_card" is simply that I did not have a GitHub-account previously. Now, when I wanted to put the record straight, and tried to open an account here, it turned out that underscores were not allowed here. So, please don't take me for an imposterer.)

@RonnyPfannschmidt
Copy link
Member

@punch-card i see what you mean, this seems a path normalization issue in local class of pylib, more investigation is needed

@pfctdayelise pfctdayelise added the platform: windows windows platform-specific problem label Jan 18, 2016
@SudhagarS
Copy link

I am getting this issue.
I have two test files with same name in two different packages.

ERROR collecting ./app/integrations/appB/tests/functional/test_handler.py
import file mismatch:
imported module 'test_handler' has this file attribute:
./app/integrations/appA/tests/functional/test_handler.py
which is not the same as the test file we want to collect:
./app/integrations/appB/tests/functional/test_handler.py

HINT: remove pycache / .pyc files and/or use a unique basename for your test file modules

@nicoddemus
Copy link
Member

nicoddemus commented Jun 23, 2017

@SudhagarS do your test directories have __init__.py files? If not adding them will fix this issue. You can read more about it in: https://docs.pytest.org/en/latest/goodpractices.html?highlight=layout#tests-as-part-of-application-code

@RonnyPfannschmidt
Copy link
Member

@nicoddemus as far as i can tell noting about that will change - there will be need for renaming

there are 2 different folders with same test structure layout in the pythonpath, so it cant be fixed

@nicoddemus
Copy link
Member

Not sure, because turning it into a package, pytest will import the module as appA.tests.functional.test_handler instead of test_handler, solving the ambiguity.

@RonnyPfannschmidt
Copy link
Member

@nicoddemus my understanding is, that both appa and appb are git checkouts that contain the testing folders pristine

@RonnyPfannschmidt
Copy link
Member

hmm, based on the stackoverflow question however, adding another init file with a explaining comment should do

@SudhagarS
Copy link

@nicoddemus Yes, that fixed it. Thanks.

@RonnyPfannschmidt
Copy link
Member

@SudhagarS can we close this then?

@SudhagarS
Copy link

So fast @RonnyPfannschmidt 🤠
Ya you can close the issue.

@RonnyPfannschmidt
Copy link
Member

thanks, also this one was just luck, i checked notifications while waiting for a build

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

No branches or pull requests

7 participants