[Chicago] Using globals across files
Chris Cope
chris at copester.com
Sun Mar 26 22:22:50 CEST 2006
I'd like to set global varibles and use them across files, but can't
find out how to do this (if it's possible). I'm using it for keeping
track of unit tests, and believe a global is the right solution, rather
than something like passing testsPassed and testsRun to Test(). Google
doesnt return a solution, just other people with the same problem. Any
ideas?
I get the error "NameError: global name 'testsPassed' is not defined"
when trying to increment it in tests.py. The code follows.
Thanks,
Chris
# File tests.py
import inspect
def Test(cond):
global testsPassed
global testsRun
if cond:
testsPassed += 1
testsRun += 1
# File MyTests.py
global testsRun
global testsPassed
testsRun = 0
testsPassed = 0
import tests
def runTest1():
x = 0
y = 0
tests.Test(x == y)
runTest1()
print "Summary:", testsPassed, "of", testsRun, "test(s) passed."
More information about the Chicago
mailing list