I figured out another option, which I like and will use for now. I'm 
sharing on here in case anyone is interested.

I just learned about execfile. Basically, I have a runtests.py file with:

import unittest
import glob
db = testDb
suite = unittest.TestSuite()
for file in glob.glob('applications/myapp/test/test*.py'):
execfile(file, globals())
unittest.TextTestRunner(verbosity=2).run(suite)


Then each file with tests just needs to be in that folder and start with 
the word test. The file would write a class extending unittest.TestCase, 
add it to suite, and beforehand would call execfile on any code in my 
models subdirectories that I want to test without having to make a request 
through the corresponding controller. An example test file would be:

# testFoo.py

 execfile('applications/myapp/models/foo/0.py')
class TestFoo(unittest.TestCase):
def setUp(self):
pass 
def test_foobar(self):
# put in whatever tests

 self.assertTrue(True)

suite.addTest(unittest.makeSuite(TestFoo))

 

 


On Monday, October 20, 2014 4:48:11 PM UTC-4, David Ripplinger wrote:
>
> Hi,
>
> I'm using unittest in my app as suggested here 
> <http://www.web2py.com/AlterEgo/default/show/260>, but I don't want all 
> my tests to be in one file. As far as I can tell, my options are:
>
>    1. Bite the bullet and put all tests in one file.
>    2. Run each test file separately and have a shell script automate over 
>    all of them. The drawback here is I can't run them as one test suite.
>    3. Put all test files in the modules folder so I can import them. The 
>    drawback here is I think that's a tacky file structure for my code. I'd 
>    rather have a test folder at the top level of the application to put stuff 
>    in.
>
> Does anyone know of a way I can get it to work with multiple test files 
> and putting them in whatever directory I wish? If not, any comments to the 
> pros and cons of the above options? What setup do you use for testing?
>
> David
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to