"""
Run this app's tests via py.test
place this file in applications/<appname>/bin/
run with: python <your web2py dir>/web2py.py -S paideia -M -R applications/<appname>/bin/runtest.py
"""
import os
import sys
import pytest
def run_pytest(w2p_dir, test_dir, app_name):
if os.name == 'nt':
errlist = (WindowsError,ValueError,SystemExit)
else:
errlist = (OSError,ValueError,SystemExit)
try:
test_dir = os.path.join(w2p_dir, 'applications', app_name, test_dir)
if test_dir not in sys.path:
sys.path.append(test_dir) # to support imports from current folder in the testfiles
# modules are applications/[app_name]/modules
modules_path = os.path.join('applications', app_name, 'modules')
if modules_path not in sys.path:
sys.path.append(modules_path) # to support imports from modules folder
if 'site-packages' not in sys.path:
sys.path.append('site-packages') # support imports from web2py/site-packages
pytest.main([test_dir]) # run pytest programmatically
except Exception, e:
print type(e), e
if __name__=='__main__':
run_pytest(<your web2py directory>, <your test folder>, <your appname>)