public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Michael Goldish <mgoldish@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: autotest@test.kernel.org, kvm@vger.kernel.org
Subject: Re: [KVM-AUTOTEST PATCH 3/7] [RFC] Introduce exception context strings
Date: Mon, 03 Jan 2011 21:48:02 +0200	[thread overview]
Message-ID: <4D2227F2.7000402@redhat.com> (raw)
In-Reply-To: <20110103192620.GJ3361@otherpad.lan.raisama.net>

On 01/03/2011 09:26 PM, Eduardo Habkost wrote:
> On Mon, Jan 03, 2011 at 08:34:07PM +0200, Michael Goldish wrote:
>> +# Exception context information:
>> +# ------------------------------
>> +# Every function can have some context string associated with it.
>> +# The context string can be changed by calling context(str) and cleared by
>> +# calling context() with no parameters.
>> +# get_context() joins the current context strings of all functions in the
>> +# provided traceback.  The result is a brief description of what the test was
>> +# doing in the provided traceback (which should be the traceback of a caught
>> +# exception).
> 
> I am sure people will eventually forget to call context() to clear
> previous context calls, and people won't notice until an actual error is
> raised on another section.
> 
> What about a decorator like:
> 
> @context("hello")
> def a()
>     ...
> 
> That would set/clear the context automatically when the function is
> called/returns?

- In most cases it isn't necessary. The context dict maps whole stack
traces to context strings, which means that if a function is called
twice from different places in the code, it won't have the same context
string.  The only problematic case is functions that are called in loops
and declare context strings.  I suppose those should be rare, and all
they need to do to prevent the problem is call error.context() at the top.
- A function can (and should) change its context string at runtime (for
example: before reboot, after reboot).  If each function could only
declare a single context, we could just use the function's name and we
wouldn't need a context.

>> +#
>> +# For example: assume a() calls b() and b() calls c().
>> +#
>> +# def a():
>> +#     error.context("hello")
>> +#     b()
>> +#     error.context("world")
>> +#     get_context() ----> 'world'
>> +#
>> +# def b():
>> +#     error.context("foo")
>> +#     c()
>> +#
>> +# def c():
>> +#     error.context("bar")
>> +#     get_context() ----> 'hello --> foo --> bar'
> 
> Above sample code is a good candidate to be in a doctest string or unit
> test, isn't it?
> 

Probably, but I've never used those before so I'll have to find out how
it's done.

  parent reply	other threads:[~2011-01-03 19:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-03 18:34 [KVM-AUTOTEST PATCH 1/7] [RFC] Fix Unhandled* exceptions Michael Goldish
2011-01-03 18:34 ` [KVM-AUTOTEST PATCH 2/7] [RFC] CmdError: remove extra blank line between methods Michael Goldish
2011-01-03 18:34 ` [KVM-AUTOTEST PATCH 3/7] [RFC] Introduce exception context strings Michael Goldish
2011-01-03 19:26   ` Eduardo Habkost
2011-01-03 19:42     ` [Autotest] " Eduardo Habkost
2011-01-03 19:48     ` Michael Goldish [this message]
2011-01-03 20:16       ` Eduardo Habkost
2011-01-03 21:07         ` Michael Goldish
2011-01-03 21:22           ` Eduardo Habkost
2011-01-03 22:06             ` [Autotest] " Eduardo Habkost
2011-01-03 22:56               ` Michael Goldish
2011-01-04 15:08                 ` Eduardo Habkost
2011-01-04 15:20                 ` Eduardo Habkost
2011-01-03 20:26   ` Eduardo Habkost
2011-01-03 20:41     ` [Autotest] " Michael Goldish
2011-01-03 18:34 ` [KVM-AUTOTEST PATCH 4/7] [RFC] Embed context information in exception strings Michael Goldish
2011-01-03 18:34 ` [KVM-AUTOTEST PATCH 5/7] [RFC] Set the .context attribute for exceptions in _call_test_function() Michael Goldish
2011-01-03 18:34 ` [KVM-AUTOTEST PATCH 6/7] [RFC] KVM test: use error.context() in migration_with_file_transfer Michael Goldish
2011-01-03 18:34 ` [KVM-AUTOTEST PATCH 7/7] [RFC] KVM test: use error.context() in kvm_preprocessing.py Michael Goldish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D2227F2.7000402@redhat.com \
    --to=mgoldish@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=ehabkost@redhat.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox