Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30787
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'value,': 0.03; 'unittest': 0.07; 'subject:How': 0.09; 'python': 0.09; 'grep': 0.09; 'itself,': 0.09; 'manuel': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:hide': 0.09; 'tuple': 0.09; 'def': 0.10; 'stack': 0.15; '__unittest': 0.16; 'editor,': 0.16; 'err': 0.16; 'err,': 0.16; 'frame,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.17; 'documented': 0.17; 'skip': 0.17; '>>>': 0.18; 'module': 0.19; 'code.': 0.20; 'variable': 0.20; 'define': 0.20; 'trace': 0.22; "user's": 0.22; 'skip:_ 20': 0.22; 'header:User-Agent:1': 0.26; 'values': 0.26; 'separate': 0.27; 'header:X-Complaints-To:1': 0.28; 'assert': 0.29; 'behaviour': 0.29; 'source': 0.29; "i'm": 0.29; 'code': 0.31; 'skip:s 30': 0.33; 'curious': 0.33; 'traceback': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'open': 0.35; 'subject:?': 0.35; 'received:org': 0.36; 'but': 0.36; 'stock': 0.36; 'method': 0.36; 'test': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'apply': 0.39; 'header:Received:5': 0.40; 'kind': 0.61; 'levels': 0.66; 'banks': 0.71; 'otten': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: How can I hide my stack frames in a TestCase subclass? |
| Date | Fri, 05 Oct 2012 10:12:54 +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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Gmane-NNTP-Posting-Host | p5084b0e4.dip.t-dialin.net |
| User-Agent | KNode/4.7.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1841.1349424768.27098.python-list@python.org> (permalink) |
| Lines | 44 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1349424768 news.xs4all.nl 6856 [2001:888:2000:d::a6]:49465 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:30787 |
Show key headers only | View raw
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