Python 如何在通过pytest使用多点访问时测量覆盖率?
我通过运行我的单元测试。我使用的保险范围 在我的一个单元测试中,我通过Python 如何在通过pytest使用多点访问时测量覆盖率?,python,unit-testing,pytest,coverage.py,pytest-cov,Python,Unit Testing,Pytest,Coverage.py,Pytest Cov,我通过运行我的单元测试。我使用的保险范围 在我的一个单元测试中,我通过multirposcessing运行函数,覆盖率并不反映通过multirposcessing运行的函数,但断言是有效的。这就是我试图解决的问题 测试结果如下: import time import multiprocessing def test_a_while_loop(): # Start through multiprocessing in order to have a timeout. p = mu
multirposcessing
运行函数,覆盖率并不反映通过multirposcessing
运行的函数,但断言是有效的。这就是我试图解决的问题
测试结果如下:
import time
import multiprocessing
def test_a_while_loop():
# Start through multiprocessing in order to have a timeout.
p = multiprocessing.Process(
target=foo
name="Foo",
)
try:
p.start()
# my timeout
time.sleep(10)
p.terminate()
finally:
# Cleanup.
p.join()
# Asserts below
...
import coverage
coverage.process_startup()
要运行测试并查看覆盖率,我在Ubuntu中使用以下命令:
coverage run --concurrency=multiprocessing -m pytest my_project/
coverage combine
coverage report
在文档中,为使覆盖率正确考虑多处理()提供了如何操作的指导。因此,我设置了一个.coveragerc
,如下所示:
[run]
concurrency = multiprocessing
[report]
show_missing = true
而且sitecustomize.py
看起来也是这样:
import time
import multiprocessing
def test_a_while_loop():
# Start through multiprocessing in order to have a timeout.
p = multiprocessing.Process(
target=foo
name="Foo",
)
try:
p.start()
# my timeout
time.sleep(10)
p.terminate()
finally:
# Cleanup.
p.join()
# Asserts below
...
import coverage
coverage.process_startup()
尽管如此,通过多处理
运行的上述函数仍然没有在覆盖范围内考虑
我做错了什么或错过了什么
p.S.似乎是一个类似的问题,但它不会再次解决我的问题:(我通过做两件事“修复”了这个问题:
流程上方,如通过其
pytest--cov=my\u proj my\u proj/