Answer a question

I am trying to debug pytest. I would like to inject an environment variable. Here is how I have set launch.json

{
    "type": "python",
    "request": "test",
    "name": "pytest",
    "console": "integratedTerminal",
    "env": {
        "ENV_VAR":"RandomStuff"
    }
},

But it seems when I start debugging. I do not see the env variable injected, as a result my test which expects that env variable fails.

Also I notice error

Could not load unit test config from launch.json

Answers

Could not really figure out how to fix "unit" test debugging with Vscode. But with Pytest one can call tests like python -m pytest <test file>(https://docs.pytest.org/en/stable/usage.html#cmdline) That means Vscode can be configured like a module

"configurations": [
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "module": "pytest",
            "args": ["--headful","--capture=no", "--html=report.html"],
        }

This is good enough to do debugging of python tests. Also you can then insert environment variables

   "env": {
        "ENV_VAR":"RandomStuff"
    }
Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐