Python 3.x 如何使单个测试在VSCode中以与在命令行上相同的方式运行?
我正在使用VisualStudio代码1.39.2和Python3.8中的Pytest6。我有这个pytest.ini文件Python 3.x 如何使单个测试在VSCode中以与在命令行上相同的方式运行?,python-3.x,visual-studio-code,plugins,pytest,conftest,Python 3.x,Visual Studio Code,Plugins,Pytest,Conftest,我正在使用VisualStudio代码1.39.2和Python3.8中的Pytest6。我有这个pytest.ini文件 [pytest] addopts = --docker-compose=./tests/docker-compose.yml --docker-compose-remove-volumes env_override_existing_values = 1 env_files = tests/.test_env 下面我在conftest.py文件的顶部有这个 def
[pytest]
addopts = --docker-compose=./tests/docker-compose.yml --docker-compose-remove-volumes
env_override_existing_values = 1
env_files =
tests/.test_env
下面我在conftest.py文件的顶部有这个
def pytest_configure(config):
use_docker = False
try:
use_docker = config.getoption("--docker-compose-remove-volumes")
except:
pass
plugin_name = 'wait_for_docker' if use_docker else 'wait_for_server'
logging.info("\n\n\ndocker value %s", use_docker)
logging.info("\n\n\n\n\nplugin name %s", plugin_name)
if not config.pluginmanager.has_plugin(plugin_name):
config.pluginmanager.import_plugin("tests.plugins.{}".format(plugin_name))
但是,仅在Visual Studio代码中,当我尝试运行测试时,通过单击编辑器中的“运行测试”或“调试测试”链接
测试在上面的最后一行进行
config.pluginmanager.import_plugin("tests.plugins.{}".format(plugin_name))
有以下错误
INTERNALERROR> ValueError: Plugin already registered: tests.plugins.wait_for_docker=<module 'tests.plugins.wait_for_docker' from '/Users/davea/Documents/workspace/my_project/tests/plugins/wait_for_docker.py'>
VS代码是否以不同的方式加载插件,或者是否有一些缓存数据需要清除才能像命令行一样工作
pytest tests/functions/test_my_stuff.py