All,

On Monday, December 17, 2012 10:11:13 PM UTC+5:30, Ian W. Scott wrote:
>
> After a bit of hacking I put together a working test runner for pytest. 
> Here it is:
>
> """
> 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
> >)
>

I realized that global "db" is available until we call pytest.main()
As soon as we are inside pytest.main() - global db object is lost.

Is there a way to preserve the globals() ?

pytest.main() is a just a function call - so ideally globals() should 
remain intact.
Any idea how to ensure that globals like db, Auth are preserved and passed 
to the py.test runtime ? (to prevent "NameError: global name 'db' is not 
defined

Thanks,
-Mandar

-- 
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