I have added a module and a test file for the module in the same directory and want to run tests from VS Code. However, upon configuring VS Code to use Python 3.8.3 (pyenv) and to use unittests there is an error in the Test Explorer that states Error discovering unittest tests (see Output > Python).
And in Output > Python
Failed to import test module: shared-scripts.utils.run_command_test
Traceback (most recent call last):
File "/Users/username/.pyenv/versions/3.8.13/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "/Users/username/.pyenv/versions/3.8.13/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/file_path/shared-scripts/utils/run_command_test.py", line 2, in <module>
import run_command
ModuleNotFoundError: No module named 'run_command'
Operating System: MacOS 12.4 (Monterey), Visual Studio Code: Version: 1.68.1
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
settings.json
{
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"*test*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
This works fine in PyCharm Community Edition and I am unsure on how to get this working on VS Code. Any suggestions?