I’d like to execute code inside my unit tests conditioned on whether they’re running from within VSCode or the command line. Is there a way to do so?
The reasoning is to add additional visual feedback through cv2.imwrite
statements, but to omit these when running a full regression from the command line or when running my CI.
I known that I can set a debugging profile inside launch.json
and define environment variables there, but this applies only when debugging a unit test:
{
"name": "Debug Tests",
"type": "python",
"request": "test",
"console": "integratedTerminal",
"python": "${command:python.interpreterPath}",
"justMyCode": false,
"env": {
"MY_ENVIRONMENT_SWITCH_FOR_WRITING_JPEGS": "1"
}
},
Is there a way to achieve something similar when not running through the debugger?
2
Answers
Try defining environment variables by using
.env
files.env:
test1.py:
Add the following to your launch.json settings:
The rest can remain the same, here is the full snippet: