YouneselBarnoussi / vscode-BDD-Python-test-adapter

MIT License
1 stars 1 forks source link

Getting Started - where are my tests #6

Closed andez2000 closed 1 year ago

andez2000 commented 1 year ago

I have VSCode installed on Windows 10:

Version: 1.77.3 (user setup)
Commit: 704ed70d4fd1c6bd6342c436f1ede30d1cff4710
Date: 2023-04-12T09:16:02.548Z
Electron: 19.1.11
Chromium: 102.0.5005.196
Node.js: 16.14.2
V8: 10.2.154.26-electron.0
OS: Windows_NT x64 10.0.19044
Sandboxed: No

I have a folder opened in VSCode containing my project with a venv setup to run my code against. At the moment I have created a feature file and step file with a simple Given When Then.

When I activate the venv and run the tests by running behave, I get the output in the terminal.

(.venv) PS C:\dev\code\playground\behave\app> behave
Feature: Foo # features/my_feature.feature:1

  Scenario: Foo  # features/my_feature.feature:3
    Given Plop   # features/steps/my_feature_steps.py:4
    When Ploop   # features/steps/my_feature_steps.py:8
    Then Ploooop # features/steps/my_feature_steps.py:12

1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
3 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.000s
(.venv) PS C:\dev\code\playground\behave\app>

My project looks like this:

├───.vscode
│       settings.json
│       
└───app
    │   main.py
    │   requirements.txt
    │           
    └───features
        │   my_feature.feature
        │   
        └───steps
                my_feature_steps.py

venv packages

behave==1.2.6
parse==1.19.0
parse-type==0.6.0
six==1.16.0

.vscode/settings.json

{
    "python.defaultInterpreterPath":"${workspaceFolder}/app/.venv/Scripts/python.exe",
    "python.terminal.activateEnvironment": true,
}

app/features/my_feature.feature

Feature: Foo

    Scenario: Foo
        Given Plop
        When Ploop
        Then Ploooop

app\features\steps\my_feature_steps.py

from behave import given, when, then

@given("Plop")
def plop(context):
    print("Plop step executed")

@when("Ploop")
def ploop(context):
    print("Ploop step executed")

@then("Ploooop")
def ploooop(context):
    print("Ploooop step executed")

Test Explorer Window

image

Extensions

Test Explorer UI v2.21.1
Python Test Explorer for Visual Studio Code v0.7.1
Behave Test Explorer v1.0.0

Where to go now?

I cannot see tests. I am not sure what I need to put in place to run this extension so I can see the tests.

In the Test Explorer - there are two options: Configure Python Tests and Install Additional Test Extensions.... If I click on Configure Python Tests then only unittest and pytest are displayed.

YouneselBarnoussi commented 1 year ago

Thanks for reporting this issue, the extension runs the behave command on the root level of the workspace. In this case, the features folder is found in the app folder and not on the root level which means the behave command can't find any feature files.

I will think of a solution, and most likely add a config to state in which folder the behave command should be run.

andez2000 commented 1 year ago

OK thank you for the quick response.

In the mean time, I have:

  1. Opened the app folder in VSCode
  2. moved my .vscode folder and changed interpreter to the new path

So the folder tree is now:

│   main.py
│   requirements.txt
│           
├───.venv
│           ...
├───.vscode
│       settings.json
│       
└───features
    │   my_feature.feature
    │   
    └───steps
            my_feature_steps.py

.vscode/settings.json

{
    "python.defaultInterpreterPath":"${workspaceFolder}/.venv/Scripts/python.exe",
    "python.terminal.activateEnvironment": true,
}

I can still run behave from the console manually. My test explorer shows as follows:

image

YouneselBarnoussi commented 1 year ago

Currently the extension doesn't use the Python interpreter specified in settings.json, it uses the global installation. This is the same issue as #2.

I will try to fix and figure out how to use the interpreter path instead as this is a pretty big issue.

andez2000 commented 1 year ago

Cool thanks.

Once behave is installed in the global pip packages:

image

I can now see the tests.

Would be great to get fix to use the settings path.

andez2000 commented 1 year ago

Amazing, thanks