Source code for webnotes.tests

"""
Run tests from modules. Sets up database connection, modules path and session before running test

Usage: from shell, run

python tests.py [test modules]

Options:
	test modules: list of modules separated by space
	
if no modules are specified, it will run all "tests.py" files from all modules
"""

import sys, os
import unittest

# webnotes path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

# modules path
import webnotes
import webnotes.defs

if webnotes.defs.__dict__.get('modules_path'):
	sys.path.append(webnotes.defs.modules_path)

[docs]def get_tests(): """ Returns list of test modules identified by "tests.py" """ ret = [] for walk_tuple in os.walk(webnotes.defs.modules_path): if 'tests.py' in walk_tuple[2]: dir_path = os.path.relpath(walk_tuple[0], webnotes.defs.modules_path) if dir_path=='.': ret.append('tests') else: ret.append(dir_path.replace('/', '.') + '.tests') return ret
[docs]def setup(): """ Sets up connection and session """ from webnotes.db import Database webnotes.conn = Database() webnotes.session = {'user':'Administrator'}
if __name__=='__main__': setup() if len(sys.argv) > 1: tests_list = sys.argv[1:] # for unittest.main sys.argv = sys.argv[:1] else: tests_list = get_tests() for tests in tests_list: exec 'from %s import *' % str(tests) unittest.main()