Да.На самом деле код из рецепта web.py Тестирование с помощью Paste и Nose можно использовать с py.test почти как есть, просто удалив импорт nose.tools
и обновив утверждения соответствующим образом.
Ноесли вы хотите знать, как писать тесты для приложений web.py в стиле py.test, они могут выглядеть следующим образом:
from paste.fixture import TestApp
# I assume the code from the question is saved in a file named app.py,
# in the same directory as the tests. From this file I'm importing the variable 'app'
from app import app
def test_index():
middleware = []
test_app = TestApp(app.wsgifunc(*middleware))
r = test_app.get('/')
assert r.status == 200
assert 'Hello, world!' in r
Поскольку вы добавите дополнительные тесты, вы, вероятно, проведете рефакторинг созданиятестовое приложение к устройству:
from pytest import fixture # added
from paste.fixture import TestApp
from app import app
def test_index(test_app):
r = test_app.get('/')
assert r.status == 200
assert 'Hello, world!' in r
@fixture()
def test_app():
middleware = []
return TestApp(app.wsgifunc(*middleware))