The project I'm working on is using a pytest test system which is fully integrated into the VSCode project. I had to add some tests which need to be executed as root because they use mininet to employ a temporary virtual network for the duration of a test. Runnig them from the commandline with sudo .venv/bin/pytest test_system.py works completley fine. When run from inside VSCode using the integrated testsystem I am unable to pass sudo to pytest. I already tried creating a wrapperfile for the pytest executable located .venv/bin/pytest and specifying this executable with "python.testing.pytestPath": "${workspaceFolder}/.venv/bin/pytest_wrapper" in VSCode's settings.json.
This approach did not work as VSCode seems to start pytest by calling pytest.main() directly bypassing the pytest executable.
I can not move the code which requires root from the test as the requirements for the virtual network employed by mininet changes from test to test and the network needs to be created at test runtime and in the test context. Furthermore the mininet python package employs a check for root permissions in its code, so allowing the user running the tests to execute the mininet cli command without needing sudo and the root password does also not work.
I am open for suggestions on how to tackle this problem. The most convenient way for me would be to create some kind of interface or wrapper to enable VSCode to run pytests with sudo.