kondratyev-nv / vscode-python-test-adapter

Python Test Adapter for the VS Code Test Explorer
https://marketplace.visualstudio.com/items?itemName=LittleFoxTeam.vscode-python-test-adapter
MIT License
117 stars 27 forks source link

Not able to pass in argument to test/pytest #269

Open g0r3 opened 2 years ago

g0r3 commented 2 years ago

Hi. I am struggling to setup the VS Test Explorer for python. While I can see and run the tests, I am not able to pass certain arguments I need When I run my pytest on a shell, I execute it in this way: python -m pytest /path/to/git/testcases/test.py --options=ignore-certificate-errors

The --options=ignore-certificate-errors makes sure that Chrome does not run in headless mode. But for some reason I am not able to pass this argument. I both have set

"python.testing.pytestArgs": ["--options=ignore-certificate-errors"],
"pythonTestExplorer.testplanArgs": ["--options=ignore-certificate-errors"],`

none of them seem to have an effect. So how would I set this argument for my pytests?

Also: It would be very nice if a feature/setting would be added, that allows to set environment variables directly inline in the (user-)settings. Right now the only way to set an environment for pytest/the test explorer seems to create an environment file and refer to it in the settings. Which is sub-optimal, if you want to have everything neat and tidy in one code-workspace file.

Thanks!

PaulWaldo commented 2 years ago

I have a similar problem populating pytest fixtures. I have tried both forms of arguments, but cannot get the tests to see them in the test explorer:

    "python.testing.pytestArgs": [
      "--without-integration",
      "--url",
      "http://127.0.0.1:5000/authentication/login",
      "--url=http://127.0.0.1:5000/authentication/login"
    ],
PaulWaldo commented 2 years ago

@g0r3 After looking further through the issues, I have found out where my problem lies. I had placed the parameters in my project.code-workspace file. I moved them to project > .vscode > settings.json and now the args are being read!

PaulWaldo commented 2 years ago

@g0r3 I spoke too soon. After restarting VS Code, my solution fails with this in the Python Log

Error 2021-10-15 09:28:46: Error discovering pytest tests:
 [r [Error]: ERROR: usage: run_adapter.py [options] [file_or_dir] [file_or_dir] [...]
run_adapter.py: error: unrecognized arguments: --url=http://127.0.0.1:5000
  inifile: None
  rootdir: /Users/paul/src/xxx/portal