【问题标题】:Pytest: how to discover filenames starting with a different prefix?Pytest:如何发现以不同前缀开头的文件名?
【发布时间】:2021-11-20 04:42:08
【问题描述】:

我正在使用 VS Code + Python 测试资源管理器扩展。

目前,只有命名约定为test_<somefilename>.py 的测试文件会被自动发现。

是否有我可以更改的设置,以便它可以检查以不同前缀开头的文件,比如moduletest_<somefilename>.py

我真的不想更改这些文件的文件名..

谢谢!

【问题讨论】:

标签: python visual-studio-code pytest


【解决方案1】:

这是我的解决方案:

  1. 在根目录创建pytest.ini,测试位于root/tests。在pytest.ini中,添加如下配置:

     [pytest]
     testpaths= tests
     python_files = moduletest_*.py
    
  2. 在 Settings.json 中,添加

    "python.testing.pytestArgs": [
        "-c",
        "pytest.ini"
     ],
     "python.testing.unittestEnabled": false,
     "python.testing.pytestEnabled": true,
    

然后打开测试资源管理器,moduletest_*.py 应该被检测到并显示在那里:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    • 1970-01-01
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多