jeudi 24 mars 2016

Why can't I reference a module (using a relative path) from it's unit tests?

I have a Python module I'm working on to add some unit tests.

The project layout looks something like this:

myproj\
    __init__.py
    myproj.py
    test\
        test_myproj.py

In test_myproj.py I'm trying to import the parent module as follows:

from .. import myproj

When I try and run it though, I get this:

Traceback (most recent call last):
  File "C:\Projects\myproj\test\test_myproj.py", line 6, in <module>
    from .. import myproj
SystemError: Parent module '' not loaded, cannot perform relative import

Various sources on the internet suggest this should work so what am I missing?

Aucun commentaire:

Enregistrer un commentaire