jimasp / behave-vsc

A vscode extension that provides a test runner/debugger and navigation for Python behave tests
https://marketplace.visualstudio.com/items?itemName=jimasp.behave-vsc
Other
15 stars 3 forks source link

"No module named 'features'" for `features` folder that is not in root #15

Closed ycsin closed 1 year ago

ycsin commented 1 year ago

Hi there, my directory structure is similar to the example-projects/project A

But my environment.py needs to import a python script (i.e. test_script1.py) in the same folder as environment.py:

from features import test_script1

It errors when I run any of the test from the plugin

    from features import test_script1
ModuleNotFoundError: No module named 'features'
Exception ModuleNotFoundError: No module named 'features'

I also have a folder (i.e. foobar) inside the features folder that contains multiple python scripts that will be used by the steps_*.py inside the step folder, which need to import them like so:

from features.foobar.something import *

Is such directory structure supported by this plugin? Thanks.

jimasp commented 1 year ago

Bear in mind that the extension itself has no knowledge of Python. It is written in TypeScript/Javascript and simply runs a Python command (using the project folder as the working directory). So any Python import errors are normally caused the same way they always are, e.g. things like having no __init__.py file in a package/module folder or vscode using the incorrect python interpreter or virtual environment etc.

If you have errors coming from Python, the first steps to diagnosing the problem would be:

  1. Try and run a test using the extension
  2. Go to the Behave VSC output window
  3. Copy the ouputted commands in that window and run them manually from a terminal (i.e. WITHOUT using the extension).

Then get the commands working without the extension. (Note that the python path in the command is set by your vscode python interpreter selection, not the extension.)

ycsin commented 1 year ago

@jimasp Thanks for the tips!