importing and nose

Andrea Crotti andrea.crotti.0 at gmail.com
Thu Jan 19 12:11:11 EST 2012


I'm writing some code to analyse pstats statistics, and I'm trying to 
have some working unit tests.
Suppose I have in the test directory another directory 'profiling', 
which contains 'x.py', and 'b.py'.

Now running the following code in a script works perfectly,

class TestStatParser(unittest.TestCase):

     def setUp(self):
         self.temp_file = tempfile.mktemp()
         prof_path = path.join(path.dirname(__file__), 'profiling')
         sys.path.append(prof_path)
         import x
         profile.run('x.f1()', filename=self.temp_file)


But running it within nose I get the following

     exec cmd in globals, locals
   File "<string>", line 1, in <module>
NameError: name 'x' is not defined


Which doesn't make sense to me, because the import doesn't actually 
fails, so
how can x not be defined???

Any clue?



More information about the Python-list mailing list