Search code examples
pythonbdd

Import module fails from the Python radish-bdd executable


I am trying to run tests in radish, a Behaviour Driven Development environment for Python, but I am failing to do even the easiest of things.

I have this structure:

.
├── features
│   └── my.feature
└── radish
    ├── __init__.py
    ├── harness
    │   ├── __init__.py
    │   └── main.py
    └── steps.py

When I do

python -c "import radish.harness"

from my working dir ".", things are fine.

When I do the same ("import radish.harness" or "import harness") in the file steps.py, I'm getting this when calling the command "radish features" from the same directory:

ModuleNotFoundError: No module named 'radish.harness'

or

ModuleNotFoundError: No module named 'harness'

The radish-bdd quick start guide quick start guide says about this:

How does radish find my python modules? radish imports all python modules inside the basedir. Per default the basedir points to $PWD/radish which in our case is perfectly fine.

Indeed a file placed in the radish directory will be imported automatically, but I am unable to import anything from within these files (apart from system libraries).

Can anyone advise me on how to import modules? I'm lost. It seems that my python knowledge on module import isn't helping.


Solution

  • I suggest you to move the 'harness' directory at the same level as 'features' and 'radish' directory.

    .
    ├── features
    │   └── my.feature
    ├── radish
    │   ├── __init__.py
    │   └── steps.py
    └── harness
        ├── __init__.py
        └── main.py
    

    If you call radish from your working dir (".") like this:

    radish -b radish features/my.feature  
    

    Then you can import your "harness" module from steps.py like this

    import harness
    

    That will work because in this case Python will find your "harness" module as it is in the current directory.