This repo is a work in progress for building a pytest plugin for web2py.
For now, pytest works, but one shall put the conftest files in the application directory.
The goal is to produce a fully independent pytest plugin.
Install requirements (preferably in a virtualenv):
pip install -r requirements.txt
Equip your application with the needed interfaces:
- a specific database setup for tests,
- a test controller to help setup and teardown database before each test (necessary for web and ui tests, as we only have acess to the application by the http protocol),
We may want to tweak the database setup to improve the speed of unit tests. A
typical setup in models/db.py
may for example looks like :
UNIT_TESTING = False
if request.TEST_APP == 'd2c84025-5e33-442d-db12-9da661250e2d':
TESTING = True
UNIT_TESTING = True
else:
import os.path
TESTING = os.path.exists("/dev/shm/web2py_test/welcome/web2py_test_indicator")
if TESTING:
if UNIT_TESTING:
# fast in memory SQL for unit test
db = DAL('sqlite:memory:', lazy_tables=True
) #
else:
db = DAL('sqlite://storage.sqlite'
, migrate_enabled=True
, lazy_tables=True) # sqlite for minimal persistence
else:
db = DAL(myconf.get('db.uri'),
pool_size=myconf.get('db.pool_size'),
migrate_enabled=myconf.get('db.migrate'),
check_reserved=['all'])
A controller is needed, whose name is defined by the test_controller
fixture (default to tests
), and shall contains a function empty_db
which
may looks like:
def empty_db():
if TESTING:
for t in db.tables:
db[t].truncate('CASCADE')
-
unit tests
py.test --w2p-app=welcome --w2p-root=tests/web2py tests/unit-tests
-
webclient tests
py.test --w2p-app=welcome --w2p-root=tests/web2py tests/web-tests/
-
UI tests TODO
-
all tests
py.test --w2p-app=welcome --w2p-root=tests/web2py tests/
TODO
TODO
TODO
Some code and inspiration taken from https://github.com/viniciusban/web2py.test
To be defined, but probably something like MIT…
See the github issues