Using py.test with coverage doesn't include imports

前端 未结 5 1960
离开以前
离开以前 2020-12-14 05:58

For Jedi we want to generate our test coverage. There is a related question in stackoverflow, but it didn\'t help.

We\'re using py.test as a test runner. However, w

5条回答
  •  我在风中等你
    2020-12-14 06:22

    I had this problem with py.test, the coverage and the django plugin. Apparently the model files are imported before coverage is started. Not even "-p coverage" for early-loading of the coverage-plugin worked.

    I fixed it (ugly?) by removing the models module from sys.modules and re-importing it in the test file that tests the model:

    import sys
    del sys.modules['project.my_app.models']
    from project.my_app import models
    
    def test_my_model():
      ...
    

提交回复
热议问题