2016-12-28 145 views
5

我們使用pytest來測試我們的項目並默認啓用--doctest-modules來收集整個項目中的所有文檔測試。我可以讓pytest doctest模塊忽略一個文件嗎?

但是有一個wsgi.py,它可能不會在測試收集期間導入,但我不能讓pytest忽略它。

我試過把它放在collect_ignore列表中conftest.py,但顯然doctest模塊不使用這個列表。

唯一能做的工作是把wsgi.py的整個目錄放到norecursedirs的pytest配置文件中,但是這顯然隱藏了我不想要的整個目錄。

有沒有辦法讓doctest模塊忽略某個文件?

回答

2

您可以使用掛鉤來有條件地從測試發現中排除某些文件夾。 https://docs.pytest.org/en/latest/writing_plugins.html

def pytest_ignore_collect(path, config): 
    """ return True to prevent considering this path for collection. 
    This hook is consulted for all files and directories prior to calling 
    more specific hooks. 
    """ 
相關問題