coverage.py does not cover script if py.test executes it from another directory

前端 未结 4 1516
眼角桃花
眼角桃花 2020-12-25 12:23

I got a python script which takes command line arguments, working with some files. I\'m writing succeeding tests with py.test putting this script through its pa

4条回答
  •  清歌不尽
    2020-12-25 12:50

    I encountered the same issue when calling "py.test --cov ..." from tox. I found a hint on this page: http://blog.ionelmc.ro/2014/05/25/python-packaging/ even though it does not mention this explicitly. Using "--develop" for tox will make sure that coverage data gathering is called from the same directory as coverage analysis. This section in tox.ini made it work for me to have a test environment for coverage:

    [tox]
    envlist = ...,py34,cov
    
    [testenv:cov]
    # necessary to make cov find the .coverage file
    # see http://blog.ionelmc.ro/2014/05/25/python-packaging/
    usedevelop = true
    commands = py.test --cov=
    deps = pytest pytest-cov
    

提交回复
热议问题