I have the following directory structure:
web2py/applications/myapp
web2py/applications/myapp/controllers/account.py
web2py/applications/myapp/models/db.py
web2py/applications/myapp/tests/runner.py
web2py/applications/myapp/tests/test_account.py
In account.py
, there is a function accessing models/db.py
, for instance
def calcExpense():
rows = db(db.expense.id >0).select()
expense = blah and blah..
return expense
In test_account.py
, I would like to test calcExpense
:
class TestAccount(unittest.TestCase):
def testCalcExpense(self):
self.assertTrue()
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestAccount))
unittest.TextTestRunner(verbosity=2).run(suite)
If I run under web2py
directory with python web2py.py -S myapp -M -R applications/myapp/tests/test_account.py
, everything is fine thanks web2py setting all required environment.
But I don't want to run unittest one way for web2py (under web2py
directory), and another way for the all other python projects (under tests
).
In particular, I want to run all tests through the test runner, under tests
by:
`python -m unittest -v runner`
How can I setup the enviroment in runner.py
, so that test_account.py
can import account.py
, account.py
have access to both db.py
and tables defined in db.py
?
Aucun commentaire:
Enregistrer un commentaire