Error on identically-named test files

Create issue
Issue #60 resolved
Andreas Kloeckner created an issue

I have two files named '' in my test tree, and pytest gives me this error mesage:

{{{ E EnvironmentError: mismatch: E imported module <module 'var-velocity' from '/tmp/regression-check/run-2009-11-12-1120/hedge/examples/advection/'> E does not stem from '/tmp/regression-check/run-2009-11-12-1120/hedge/examples/wave/' E maybe files are missing?

env/lib/python2.5/site-packages/py-1.1.0-py2.5.egg/py/impl/path/ EnvironmentError }}}

Comments (9)

  1. Holger Krekel repo owner
    • changed status to open

    i am not exactly sure about the context/test-configuration you are using here but this error is raised where test modules are imported. After import py.test checks if the module really comes from the test module file. Otherwise it indicates that a module with the name has been imported from a different place (and Python's sys.modules caches such imports globally by name as you probably know). This situation usually is an error, is that different in your case?

  2. Andreas Kloeckner reporter

    If I have two files, say


    that are being found within one py.test run, then I'd have a hard time considering a name clash an error. (though in my specific case it was more like



    As for the module cache: For test modules, I don't see it providing much benefit, as they are likely to be imported exactly once.

  3. Holger Krekel repo owner

    Some people have test modules that import each other like this:

       from test_something import common_helper_code
       ... use common_helper_code ...

    in which case one gets (possibly weird) rrors if the other test directory has already been run and a test module with an identical name already been impoted (or vice versa) Nose solves this by manually unloading each test module and re-loading it but this has issues in more complex settings.

    py.test tries to be strict and simple here and not do any unload/reload magic with test modules. Usually, adding an solves the ambiguity so i don't currently consider it too harsh a restriction.

    Thus i tentatively close the issue but remain open to re-discuss it if you continue to see a real need.

  4. balinares


    I'm using the doctest collector and I'm having the same problem as reported here, I think, with the file of a module, so no luck renaming it:

    self = local('/home/me/spyrit-dev/_commands/')
    modname = '_commands.__init__', ensuresyspath = True
    >   ???
    E   ImportMismatchError: ('_commands.__init__', '/home/me/spyrit-dev/_commands', local('/home/me/spyrit-dev/_commands/'))

    What's going on here, then? What can I do?

  5. Holger Krekel repo owner
    • changed status to open

    could you provide the directory layout you are using and the py.test invocation including the cwd?

  6. Holger Krekel repo owner

    also it'd be interesting if you upgrade py with "pip install -U py" or "easy_install -U py" to get py-1.3.2 instead of 1.1

  7. Log in to comment