Peter Otten scripsit : > Manuel Pégourié-Gonnard wrote: > >> Peter Otten scripsit : >> >>> __unittest = True >>> >> Hum, is it documented somewhere? I can't find it in the doc. Also, I'm >> curious to know what kind of magic it's using. > > I took advantage of the fact that Python is open source and had a look into > the source code ;) > Fair enough.
However, there was an implied question in the "documented" part: can we rely on it? Isn't it considered an implementation detail (names starting with underscores)? > $ cd /usr/lib/python2.7/unittest > $ grep frame *.py -C2 > ... > result.py- > result.py- def _is_relevant_tb_level(self, tb): > result.py: return '__unittest' in tb.tb_frame.f_globals > result.py- > ... > > $ grep _is_relevant_tb_level *.py -C5 > result.py- > result.py- def _exc_info_to_string(self, err, test): > result.py- """Converts a sys.exc_info()-style tuple of values into a > string.""" > result.py- exctype, value, tb = err > result.py- # Skip test runner traceback levels > result.py: while tb and self._is_relevant_tb_level(tb): > result.py- tb = tb.tb_next > result.py- > ... > > And so on. I actually used an editor, not grep -- but you get the idea. Sure, thanks. -- Manuel Pégourié-Gonnard - http://people.math.jussieu.fr/~mpg/ -- http://mail.python.org/mailman/listinfo/python-list