Error on identically-named test files

Issue #60 resolved
Andreas Kloeckner
created an issue

I have two files named 'var-velocity.py' 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/var-velocity.py'> E does not stem from '/tmp/regression-check/run-2009-11-12-1120/hedge/examples/wave/var-velocity.py' E maybe init.py files are missing?

env/lib/python2.5/site-packages/py-1.1.0-py2.5.egg/py/impl/path/local.py:528: 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

    project1/test/test-something.py
    project2/test/test-something.py
    

    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

    project1/subproject1/test-something.py
    project1/subproject2/test-something.py
    

    )

    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 init.py 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

    Hi,

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

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

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

  5. Log in to comment