1

我将 Visual Studio Code 1.39.2 和 PyTest 6 与 Python 3.8 一起使用。我有这个 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_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 Code 中,当我尝试运行测试时,通过单击编辑器中的“运行测试”或“调试测试”链接...

在此处输入图像描述

测试在上面的最后一行终止......

    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'>

如果我在命令行上自行运行测试,则不会发生这种情况......

pytest tests/functions/test_my_stuff.py

VS Code 是否以不同的方式加载插件,或者是否需要清除一些缓存数据才能像命令行一样工作?

4

0 回答 0