[TIP] Coming changes to unittest2 plugins

Michael Foord michael at voidspace.org.uk
Mon Sep 27 07:33:58 PDT 2010

  Hello all,

After recent conversations with Holger Krekel and Robert Collins I have 
decided to make a fairly major internal changes to unittest2 plugins. 
I'm getting rid of all global state, which includes the global hooks 
that are currently the core of the extension machinery.

Getting rid of global state always *sounds goood*, but it isn't without 
API consequences. With no global access to the hooks set it needs to be 
passed down and 'made available' to the runner, loader, suites and all 
test cases. This is annoying, but probably still better than global 
state. Removing the global state makes *testing* the plugin machinery 
massively easier however... It also allows multiple different plugin 
configurations within the same process (which is nice but only actually 
useful for a small set of use cases).

This refactoring also means changing the way plugins are initialized, 
merely importing the plugin is no longer enough (the metaclass goes - 
which makes me sad but is probably also a good thing). I expect to 
change configuration to look like:


I hate the colon but it is how entry points do it *anyway*. Function 
based plugins will still be possible, but will *require* an 
initialization function that takes the hook set.

With no global state we also can't have global "add command line option" 
functions and we can't have a global config structure. These need to be 
associated with a plugin-configuration-context (or whatever I call it - 
currently PluginManager which I also hate). The command line option 
functions and access to the configuration will likely become methods on 
the Plugin class, so actually a bit easier to use - but another change.

I'm part way through this. (In my local repo *everything* is broken.) 
I'll be sure to make the announcement when it is done...

The nicest part of the change is that the really horrible internal 
tangle of the messaging API (the only part of the plugin system I was 
really unhappy with) can be cleaned up, so definitely a nett win.

All the best,

Michael Foord


READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.

More information about the testing-in-python mailing list