How to propagate a web2py enviroment to several test modules?

35 views
Skip to first unread message

AlighaThor

unread,
Jul 27, 2016, 2:56:32 AM7/27/16
to web2py-users
Hi. Here's my question:
¿How do I propagate my web2py enviroment to several test modules?
Following this recipe im starting doing TDD with web2py.

My problem is that Im organizing my test cases in several modules, so im only executing my main test runner:

-S bodega -M -R applications/bodega/tests/run_tests.py

So, in the module run_tests.py im discovering my test modules with PyTest:

import pytest

pytest.main('applications/bodega/tests')

That's it. The problem is that in my test files Im unable to "see" the web2py globals variables. So, ¿How do I propagate it to them?

Thanks!

Dave S

unread,
Jul 27, 2016, 1:39:39 PM7/27/16
to web...@googlegroups.com

The usual way to share the globals is via the object called "current" :

<URL:http://web2py.com/books/default/chapter/29/04/the-core#Sharing-the-global-scope-with-modules-using-the-current-object>

For instance, in my models/scheduler.py I have the task wrapper that the scheduler calls,  which does

from gluon import current
from mymodule import myfunc

def mytask(...):
  current
.db = db
  current
.uuid = request._uuid
  etc
()
  myfunc
()
  etc2
()
 
return stuff


modules/mymodule.py has

from gluon import current

def myfunc(...):
  db
= current.db
  morestuff
 
return thisandthat




/dps

Reply all
Reply to author
Forward
0 new messages