Python 有没有办法设置pytest来运行webapp2服务器以获取覆盖率报告?

Python 有没有办法设置pytest来运行webapp2服务器以获取覆盖率报告?,python,google-app-engine,code-coverage,pytest,Python,Google App Engine,Code Coverage,Pytest,我目前正在为webapp2服务器设置自动测试,我想获得一份覆盖率报告。我使用的是pytest和pytest coverage,它适用于本地代码,但问题是我向服务器发出请求(在本地运行),而服务器运行的代码不包含在coverage报告中。有没有一种方法可以设置pytest来运行服务器本身,这样我就可以在覆盖率报告中包含处理程序等?如果有人处于类似情况,可以在这里使用。您可以编写一个简单的fixture,如下所示,以启动服务器实例并使其在测试中可用: # content of conftest.py

我目前正在为webapp2服务器设置自动测试,我想获得一份覆盖率报告。我使用的是pytest和pytest coverage,它适用于本地代码,但问题是我向服务器发出请求(在本地运行),而服务器运行的代码不包含在coverage报告中。有没有一种方法可以设置pytest来运行服务器本身,这样我就可以在覆盖率报告中包含处理程序等?

如果有人处于类似情况,可以在这里使用。您可以编写一个简单的fixture,如下所示,以启动服务器实例并使其在测试中可用:

# content of conftest.py

import pytest
from xprocess import ProcessStarter

@pytest.fixture
def myserver(xprocess):
    class Starter(ProcessStarter):
        # startup pattern
        pattern = "PATTERN"

        # command to start process
        args = ['command', 'arg1', 'arg2']

    # ensure process is running and return its logfile
    logfile = xprocess.ensure("myserver", Starter)

    conn = # create a connection or url/port info to the server
    yield conn

    # clean up whole process tree afterwards
    xprocess.getinfo("myserver").terminate()