-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Argument filtering for pytest fails to handle custom arguments #11736
Comments
@omartin2010 You have to split these into separate arguments. Right now it is treating
|
if I do that, it doesn't work, I get this :
Turns out I also have another argument that needs to be there which is the directory that contains the tests, so my args are :
With or without the |
Looking at pytest's help i don't see a
Try this:
|
I think I may have been unclear. This is for my own, user defined parameter, one one for pytest itself, so that a fixture can retrieve it in this kind of a function. Here is an extract of my
so that it's passed to my pytest session. So I want this param to pass straight to my stuff. So far it works when I run this from the command line, just not when from vscode... |
Looks like the bug is in
We pass the config_file arguments there and we don't get back the expected arguments. In the case of :
Expected:
Actual:
Not sure why it prints out the command twice with different arguments. |
I have a similar issue, I also try to provide custom defined options to my tests and the discovery doesn't forward them correctly, so pytest raises an error and no tests will be found. My setup is almost identical to the description above. In addition I allowed the config names to be specified via environment variables which is the only way to get it to work! I had to default to # conftest.py
def pytest_addoption(parser):
def environ_or_required(key: str) -> Dict[str, Any]:
return (
{"default": os.environ.get(key)}
if key in os.environ
else {"required": True}
)
parser.addoption(
"--discord-token",
type=str,
help="discord bot token",
**environ_or_required("DISCORD_TOKEN"),
)
parser.addoption(
"--discord-channel",
type=str,
help="discord bot channel name or id",
**environ_or_required("DISCORD_CHANNEL"),
)
@pytest.fixture(autouse=True)
def env_setup(monkeypatch: pytest.MonkeyPatch, request: pytest.FixtureRequest):
monkeypatch.setenv("DISCORD_TOKEN", request.config.getoption("--discord-token"))
monkeypatch.setenv("DISCORD_CHANNEL", request.config.getoption("--discord-channel")) // settings.json
{
"python.pythonPath": "venv/bin/python",
"restructuredtext.confPath": "",
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"--discord-token",
"my-private-token",
"--discord-channel",
"Allgemein",
],
} And one error message: python /home/user/.vscode-server/extensions/ms-python.python-2020.12.424452561/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /mnt/c/work/project/python-transformer-discord-notifier -s
Test Discovery failed:
Error: ERROR: usage: run_adapter.py [options] [file_or_dir] [file_or_dir] [...]
run_adapter.py: error: the following arguments are required: --discord-token, --discord-channel
Traceback (most recent call last):
File "/home/user/.vscode-server/extensions/ms-python.python-2020.12.424452561/pythonFiles/testing_tools/run_adapter.py", line 22, in <module>
main(tool, cmd, subargs, toolargs)
File "/home/user/.vscode-server/extensions/ms-python.python-2020.12.424452561/pythonFiles/testing_tools/adapter/__main__.py", line 100, in main
parents, result = run(toolargs, **subargs)
File "/home/user/.vscode-server/extensions/ms-python.python-2020.12.424452561/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 44, in discover
raise Exception("pytest discovery failed (exit code {})".format(ec))
Exception: pytest discovery failed (exit code 4) I have to add that I have to restart VSCode else the changes in
Configuring it like so also fails: (sometimes with a different message...) "python.testing.pytestArgs": [
"--discord-token 'my-private-token'",
"--discord-channel Allgemein",
], python /home/user/.vscode-server/extensions/ms-python.python-2020.12.424452561/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /mnt/c/work/project/python-transformer-discord-notifier -s --cache-clear --discord-token 'my-private-token' --discord-channel Allgemein
Test Discovery failed:
Error: ============================= test session starts ==============================
platform linux -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: /mnt/c/work/project/python-transformer-discord-notifier, configfile: setup.cfg
plugins: cov-2.10.1
collected 0 items
========================= no tests collected in 0.07s ==========================
ERROR: file or directory not found: --discord-token 'my-private-token' (Using Are others having the same issue? |
I'm also facing this issue.
Triggers error:
|
@ralwing that seems to be error coming from |
Having a very similar problem: These are all ignored - not matter what I do with them, they do not effect running tests either with "run test" or "debug test" window 10, vs code 1.58.2 |
same issue |
@karthiknadig any movement on this issue. It cropped up in regards with another issue as well |
We are in the process of re-writing the testing adapter #17242 . It is actively being worked on in the current milestone. |
@karthiknadig - as a fellow open-sourcer - happy to play guinea pig 😉 - thanks for your work |
Until a fix available, you can add these options on
|
So basically I can't dynamically choose between two different implementations like: |
Has there been any movement on this? I can't get any of the suggestions or workarounds to work (VS Code Version: 1.80.2) |
I created a proposal with a solution for this problem, would love your input on the above issue! #21845 |
I was able to use this format to get around it:
|
Issue Type: Bug
I created a fixture in
conftest.py
that reads at input args topytest
(usingpytest_addoption
. See code below. When I try and add this option to mysettings.json
file so that my tests execute properly, it fails with the ERROR: file not found...Here is my
conftest.py
file :And then my
settings.json
relevant to this:And finally the output of the console :
Running pytest version 5.4.2. Feels to me like this option is taken as if it were a file to test, versus an actual argument. Ideas? Am I missing something?
Extension version: 2020.4.76186
VS Code version: Code - Insiders 1.46.0-insider (d487078dc7fc1c276657cadb61b4f63833a8df55, 2020-05-07T16:19:54.327Z)
OS version: Windows_NT x64 10.0.18363
Remote OS version: Linux arm64 4.9.140-tegra
Remote OS version: Linux arm64 4.9.140-tegra
System Info
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: enabled
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off_ok
webgl: enabled
webgl2: enabled
The text was updated successfully, but these errors were encountered: