Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Falcon,wsgiref:单元测试用例_Python_Unit Testing_Pytest_Falconframework_Wsgiref - Fatal编程技术网

Python Falcon,wsgiref:单元测试用例

Python Falcon,wsgiref:单元测试用例,python,unit-testing,pytest,falconframework,wsgiref,Python,Unit Testing,Pytest,Falconframework,Wsgiref,我有以下代码: master.py def create(): master = falcon.API(middleware=Auth()) msg = Message() master.add_route('/message', msg) master = create() if __name__ == '__main__': httpd = simple_server.make_server("127.0.0.1", 8989, master)

我有以下代码:

master.py    

def create():
    master = falcon.API(middleware=Auth())
    msg = Message()
    master.add_route('/message', msg)


master = create()

if __name__ == '__main__':
    httpd = simple_server.make_server("127.0.0.1", 8989, master)
    process = Thread(target=httpd.serve_forever, name="master_process")
    process.start()

    #Some logic happens here
    s_process = Thread(target=httpd.shutdown(), name="shut_process")
    s_process.start()
    s.join()
我尝试为以下项目创建以下测试用例:

from falcon import testing
from master import create

@pytest.fixture(scope='module')
def client():
   return testing.TestClient(create())

def test_post_message(client):
   result = client.simulate_post('/message', headers={'token': "ubxuybcwe"}, body='{"message": "I'm here!"}') --> This line throws the error
   assert result.status_code == 200
我尝试运行上述操作,但出现以下错误:

TypeError: 'NoneType' object is not callable

实际上,我不知道应该如何编写这个测试用例

根据@hoefling所说的,下面的人修复了它:

master.py    

def create():
     master = falcon.API(middleware=Auth())
     msg = Message()
     master.add_route('/message', msg)
     return master


master = create()


if __name__ == '__main__':
    httpd = simple_server.make_server("127.0.0.1", 8989, master)
    process = Thread(target=httpd.serve_forever, name="master_process")
    process.start()

    #Some logic happens here
    s_process = Thread(target=httpd.shutdown(), name="shut_process")
    s_process.start()
    s.join()
然后测试用例工作:

from falcon import testing
from master import create

@pytest.fixture(scope='module')
def client():
    return testing.TestClient(create())

def test_post_message(client):
    result = client.simulate_post('/message', headers={'token': "ubxuybcwe"}, 
    body='{"message": "I'm here!"}') 
    assert result.status_code == 200

非常感谢@hoefling

这是因为在
create()
中没有返回任何内容。添加
returnmaster
应该可以修复它。谢谢!!这样愚蠢的错误。让我输入正确的代码。