Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30787
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: How can I hide my stack frames in a TestCase subclass? |
| Date | 2012-10-05 10:12 +0200 |
| Organization | None |
| References | <52b17563-966c-46bc-bd77-da29e944c909@googlegroups.com> <mailman.1826.1349400392.27098.python-list@python.org> <k4lum6$c9q$1@thue.elzevir.fr> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1841.1349424768.27098.python-list@python.org> (permalink) |
Manuel Pégourié-Gonnard wrote: > Peter Otten scripsit : > >> David Banks wrote: >> >>> Note that the custom assert method causes a stack trace with two frames, >>> one inside the method itself, whereas the stock unittest method only has >>> one frame, the relevant line in the user's code. How can I apply this >>> frame-hiding behaviour to my own method? >> >> Move MyTestCase in a separate module and define a global variable >> >> __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 ;) $ 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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How can I hide my stack frames in a TestCase subclass? David Banks <amoebae@gmail.com> - 2012-10-04 08:53 -0700
Re: How can I hide my stack frames in a TestCase subclass? Peter Otten <__peter__@web.de> - 2012-10-05 00:41 +0200
Re: How can I hide my stack frames in a TestCase subclass? Manuel Pégourié-Gonnard <mpg@elzevir.fr> - 2012-10-05 08:28 +0200
Re: How can I hide my stack frames in a TestCase subclass? Peter Otten <__peter__@web.de> - 2012-10-05 10:12 +0200
Re: How can I hide my stack frames in a TestCase subclass? Manuel Pégourié-Gonnard <mpg@elzevir.fr> - 2012-10-05 10:50 +0200
Re: How can I hide my stack frames in a TestCase subclass? Peter Otten <__peter__@web.de> - 2012-10-05 11:26 +0200
csiph-web