You are missing a few steps.
Your program does nothing, because you did not tell it to do anything, you just defined a class. So let him tell you something to do. We will use the unittest package to make things a little more automatic.
import unittest from webtest import TestApp class MyTests(unittest.TestCase): def test_admin_login(self): resp = self.TestApp.get('/admin') print (resp.request) if __name__ == '__main__': unittest.main()
Run this and we see:
E ====================================================================== ERROR: test_admin_login (__main__.MyTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_foo.py", line 6, in test_admin_login resp = self.TestApp.get('/admin') AttributeError: 'MyTests' object has no attribute 'TestApp' ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (errors=1)
Ok, so we need a testing app. Where to get it? Usually you need the WSGI application to be created in main via config.make_wsgi_app() . The easiest way is to download it, just like pserve development.ini , when you launch the application. We can do this through pyramid.paster.get_app() .
import unittest from pyramid.paster import get_app from webtest import TestApp class MyTests(unittest.TestCase): def test_admin_login(self): app = get_app('testing.ini') test_app = TestApp(app) resp = test_app.get('/admin') self.assertEqual(resp.status_code, 200) if __name__ == '__main__': unittest.main()
Now all you need is an INI file, similar to your development.ini , but for testing purposes. You can simply copy development.ini until you need to set any settings just for testing.
Hope this gives you a starting point to learn more about unittest .
source share