How to speed up pytest

前端 未结 7 647
醉梦人生
醉梦人生 2020-12-09 01:14

Is there some way to speed up the repeated execution of pytest? It seems to spend a lot of time collecting tests, even if I specify which files to execute on th

相关标签:
7条回答
  • 2020-12-09 01:52

    I was having the same problem where I was calling pytest at the root of my project and my tests were three subdirectories down. The collection was taking 6-7 seconds before 0.4 seconds of actual test execution.

    My solution initially was to call pytest with the relative path to the tests:

    pytest src/www/tests/
    

    If doing that speeds up your collection also, you can add the relative path to the tests to the end of the addopts setting in your pytest.ini - eg:

    [pytest]
    addopts = --doctest-glob='test_*.md' -x src/www/tests/
    

    This dropped the collection + execution time down to about a second and I could still just call pytest as I was before.

    0 讨论(0)
提交回复
热议问题