1 Using custom plugins without setuptools
2 ---------------------------------------
4 If you have one or more custom plugins that you'd like to use with nose, but
5 can't or don't want to register that plugin as a setuptools entrypoint, you
6 can use the ``addplugins`` keyword argument to :func:`nose.core.main` or
7 :func:`nose.core.run` to make the plugins available.
9 To do this you would construct a launcher script for nose, something like::
12 from yourpackage import YourPlugin, YourOtherPlugin
14 if __name__ == '__main__':
15 nose.main(addplugins=[YourPlugin(), YourOtherPlugin()])
17 Here's an example. Say that you don't like the fact that the collect-only
18 plugin outputs 'ok' for each test it finds; instead you want it to output
19 'maybe.' You could modify the plugin itself, or instead, create a Maybe plugin
20 that transforms the output into your desired shape.
22 Without the plugin, we get 'ok.'
25 >>> support = os.path.join(os.path.dirname(__file__), 'support')
26 >>> from nose.plugins.plugintest import run_buffered as run
27 >>> argv = [__file__, '-v', support] # --collect-only
31 ----------------------------------------------------------------------
36 Without '-v', we get a dot.
38 >>> run(argv=[__file__, support])
40 ----------------------------------------------------------------------
45 The plugin is simple. It captures and wraps the test result output stream and
46 replaces 'ok' with 'maybe' and '.' with '?'.
48 >>> from nose.plugins.base import Plugin
49 >>> class Maybe(Plugin):
50 ... def setOutputStream(self, stream):
51 ... self.stream = stream
54 ... self.stream.flush()
55 ... def writeln(self, out=""):
56 ... self.write(out + "\n")
57 ... def write(self, out):
62 ... self.stream.write(out)
64 To activate the plugin, we pass an instance in the addplugins list.
66 >>> run(argv=argv + ['--with-maybe'], addplugins=[Maybe()])
69 ----------------------------------------------------------------------
74 >>> run(argv=[__file__, support, '--with-maybe'], addplugins=[Maybe()])
76 ----------------------------------------------------------------------