/usr/share/doc/python-nose2/html/configuration.html is in python-nose2-doc 0.7.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | <!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Configuring nose2 — nose2 0.6.0 documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="genindex.html"/>
<link rel="search" title="Search" href="search.html"/>
<link rel="top" title="nose2 0.6.0 documentation" href="index.html"/>
<link rel="next" title="Differences: nose2 vs nose vs unittest2" href="differences.html"/>
<link rel="prev" title="Using nose2" href="usage.html"/>
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> nose2
</a>
<div class="version">
0.6
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="getting_started.html">Getting started with nose2</a></li>
<li class="toctree-l1"><a class="reference internal" href="usage.html">Using nose2</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Configuring nose2</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#configuration-files">Configuration Files</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#configuring-test-discovery">Configuring Test Discovery</a></li>
<li class="toctree-l3"><a class="reference internal" href="#specifying-plugins-to-load">Specifying Plugins to Load</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#configuring-plugins">Configuring Plugins</a></li>
<li class="toctree-l2"><a class="reference internal" href="#test-runner-tips-and-tweaks">Test Runner Tips and Tweaks</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#running-tests-in-a-single-module">Running Tests in a Single Module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#rolling-your-own-runner">Rolling Your Own Runner</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#altering-the-default-plugin-set">Altering the Default Plugin Set</a></li>
<li class="toctree-l4"><a class="reference internal" href="#when-loading-plugins-from-modules-is-not-enough">When Loading Plugins from Modules is not Enough</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="differences.html">Differences: nose2 vs nose vs unittest2</a></li>
<li class="toctree-l1"><a class="reference internal" href="plugins.html">Plugins for nose2</a></li>
<li class="toctree-l1"><a class="reference internal" href="tools.html">Tools and Helpers</a></li>
<li class="toctree-l1"><a class="reference internal" href="changelog.html">Changelog</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="dev/writing_plugins.html">Writing Plugins</a></li>
<li class="toctree-l1"><a class="reference internal" href="dev/documenting_plugins.html">Documenting plugins</a></li>
<li class="toctree-l1"><a class="reference internal" href="dev/event_reference.html">Event reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="dev/hook_reference.html">Hook reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="dev/session_reference.html">Session reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="dev/plugin_class_reference.html">Plugin class reference</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="dev/contributing.html">Contributing to nose2</a></li>
<li class="toctree-l1"><a class="reference internal" href="dev/internals.html">Internals</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">nose2</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Configuring nose2</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/configuration.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="configuring-nose2">
<h1>Configuring nose2<a class="headerlink" href="#configuring-nose2" title="Permalink to this headline">¶</a></h1>
<div class="section" id="configuration-files">
<h2>Configuration Files<a class="headerlink" href="#configuration-files" title="Permalink to this headline">¶</a></h2>
<p>Most configuration of nose2 is done via config files. These are
standard, .ini-style config files, with sections marked off by
brackets (“<code class="docutils literal"><span class="pre">[unittest]</span></code>”) and <code class="docutils literal"><span class="pre">key</span> <span class="pre">=</span> <span class="pre">value</span></code> pairs within those sections.
When the value is a list, put each value into its own line with proper
indentation</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">key_expecting_list</span> <span class="o">=</span> <span class="n">value1</span>
<span class="n">value2</span>
</pre></div>
</div>
<p>Two command line options, <a class="reference internal" href="#cmdoption-c"><code class="xref std std-option docutils literal"><span class="pre">-c</span></code></a> and <a class="reference internal" href="#cmdoption-no-user-config"><code class="xref std std-option docutils literal"><span class="pre">--no-user-config</span></code></a>
may be used to determine which config files are loaded.</p>
<dl class="cmdoption">
<dt id="cmdoption-c">
<code class="descname">-c</code><code class="descclassname"> CONFIG</code><code class="descclassname">, </code><code class="descname">--config</code><code class="descclassname"> CONFIG</code><a class="headerlink" href="#cmdoption-c" title="Permalink to this definition">¶</a></dt>
<dd><p>Config files to load. Default behavior is to look for
<code class="docutils literal"><span class="pre">unittest.cfg</span></code> and <code class="docutils literal"><span class="pre">nose2.cfg</span></code> in the start directory, as well
as any user config files (unless <a class="reference internal" href="#cmdoption-no-user-config"><code class="xref std std-option docutils literal"><span class="pre">--no-user-config</span></code></a> is
selected).</p>
</dd></dl>
<dl class="cmdoption">
<dt id="cmdoption-no-user-config">
<code class="descname">--no-user-config</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-no-user-config" title="Permalink to this definition">¶</a></dt>
<dd><p>Do not load user config files. If not specified, in addition to the
standard config files and any specified with <a class="reference internal" href="#cmdoption-c"><code class="xref std std-option docutils literal"><span class="pre">-c</span></code></a>, nose2
will look for <code class="docutils literal"><span class="pre">.unittest.cfg</span></code> and <code class="docutils literal"><span class="pre">.nose2.cfg</span></code> in the user’s
$HOME directory.</p>
</dd></dl>
<div class="section" id="configuring-test-discovery">
<h3>Configuring Test Discovery<a class="headerlink" href="#configuring-test-discovery" title="Permalink to this headline">¶</a></h3>
<p>The <code class="docutils literal"><span class="pre">[unittest]</span></code> section of nose2 config files is used to configure
nose2 itself. The following options are available to configure test
discovery:</p>
<dl class="configvar">
<dt id="configvar-start-dir">
<code class="descname">start-dir</code><a class="headerlink" href="#configvar-start-dir" title="Permalink to this definition">¶</a></dt>
<dd><p>This option configures the default directory to start discovery.
The default value is <code class="docutils literal"><span class="pre">"."</span></code> (the current directory where nose2
is executed). This directory is where nose2 will start looking for
tests.</p>
</dd></dl>
<dl class="configvar">
<dt id="configvar-code-directories">
<code class="descname">code-directories</code><a class="headerlink" href="#configvar-code-directories" title="Permalink to this definition">¶</a></dt>
<dd><p>This option configures nose2 to add the named directories to
sys.path and the discovery path. Use this if your project has
code in a location other than the top level of the project, or the
directories <code class="docutils literal"><span class="pre">lib</span></code> or <code class="docutils literal"><span class="pre">src</span></code>. The value here may be a list: put each
directory on its own line in the config file.</p>
</dd></dl>
<dl class="configvar">
<dt id="configvar-test-file-pattern">
<code class="descname">test-file-pattern</code><a class="headerlink" href="#configvar-test-file-pattern" title="Permalink to this definition">¶</a></dt>
<dd><p>This option configures how nose detects test modules. It is a file
glob.</p>
</dd></dl>
<dl class="configvar">
<dt id="configvar-test-method-prefix">
<code class="descname">test-method-prefix</code><a class="headerlink" href="#configvar-test-method-prefix" title="Permalink to this definition">¶</a></dt>
<dd><p>This option configures how nose detects test functions and
methods. The prefix set here will be matched (via simple string
matching) against the start of the name of each method in test
cases and each function in test modules.</p>
</dd></dl>
<p>Examples:</p>
<div class="highlight-ini"><div class="highlight"><pre><span></span><span class="k">[unittest]</span>
<span class="na">start-dir</span> <span class="o">=</span> <span class="s">tests</span>
<span class="na">code-directories</span> <span class="o">=</span> <span class="s">source</span>
<span class="s"> more_source</span>
<span class="na">test-file-pattern</span> <span class="o">=</span> <span class="s">*_test.py</span>
<span class="na">test-method-prefix</span> <span class="o">=</span> <span class="s">t</span>
</pre></div>
</div>
</div>
<div class="section" id="specifying-plugins-to-load">
<h3>Specifying Plugins to Load<a class="headerlink" href="#specifying-plugins-to-load" title="Permalink to this headline">¶</a></h3>
<p>To avoid loading any plugins, use the <a class="reference internal" href="#cmdoption-no-plugins"><code class="xref std std-option docutils literal"><span class="pre">--no-plugins</span></code></a>
option. Beware, though: nose2 does all test discovery and loading via
plugins, so unless you are patching in a custom test loader and
runner, when run with <a class="reference internal" href="#cmdoption-no-plugins"><code class="xref std std-option docutils literal"><span class="pre">--no-plugins</span></code></a>, nose2 will do nothing.</p>
<dl class="cmdoption">
<dt id="cmdoption-no-plugins">
<code class="descname">--no-plugins</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-no-plugins" title="Permalink to this definition">¶</a></dt>
<dd><p>Do not load any plugins. <em>This kills the nose2.</em></p>
</dd></dl>
<p>To specify plugins to load beyond the builtin plugins automatically
loaded, add a <a class="reference internal" href="#configvar-plugins"><code class="xref std std-config docutils literal"><span class="pre">plugins</span></code></a> entry under the <code class="docutils literal"><span class="pre">[unittest]</span></code>
section in a config file.</p>
<dl class="configvar">
<dt id="configvar-plugins">
<code class="descname">plugins</code><a class="headerlink" href="#configvar-plugins" title="Permalink to this definition">¶</a></dt>
<dd><p>List of plugins to load. Put one plugin module on each line.</p>
</dd></dl>
<p>To exclude some plugins that would otherwise be loaded, add an
<a class="reference internal" href="#configvar-exclude-plugins"><code class="xref std std-config docutils literal"><span class="pre">exclude-plugins</span></code></a> entry under the <code class="docutils literal"><span class="pre">[unittest]</span></code>
section in a config file.</p>
<dl class="configvar">
<dt id="configvar-exclude-plugins">
<code class="descname">exclude-plugins</code><a class="headerlink" href="#configvar-exclude-plugins" title="Permalink to this definition">¶</a></dt>
<dd><p>List of plugins to exclude. Put one plugin module on each line.</p>
</dd></dl>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">It bears repeating that in both <a class="reference internal" href="#configvar-plugins"><code class="xref std std-config docutils literal"><span class="pre">plugins</span></code></a> and
<a class="reference internal" href="#configvar-exclude-plugins"><code class="xref std std-config docutils literal"><span class="pre">exclude-plugins</span></code></a> entries, you specify the plugin <em>module</em>,
not the plugin <em>class</em>.
The module is specified by the (dot-separated) <em>fully qualified</em> name.</p>
</div>
<p>Examples:</p>
<div class="highlight-ini"><div class="highlight"><pre><span></span><span class="k">[unittest]</span>
<span class="na">plugins</span> <span class="o">=</span> <span class="s">myproject.plugins.frobulate</span>
<span class="s"> otherproject.contrib.plugins.derper</span>
<span class="na">exclude-plugins</span> <span class="o">=</span> <span class="s">nose2.plugins.loader.functions</span>
<span class="s"> nose2.plugins.outcomes</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="configuring-plugins">
<h2>Configuring Plugins<a class="headerlink" href="#configuring-plugins" title="Permalink to this headline">¶</a></h2>
<p>Most plugins specify a config file section that may be used to
configure the plugin. If nothing else, any plugin that specifies a
config file section can be set to automatically register by including
<code class="docutils literal"><span class="pre">always-on</span> <span class="pre">=</span> <span class="pre">True</span></code> in its config:</p>
<div class="highlight-ini"><div class="highlight"><pre><span></span><span class="k">[my-plugin]</span>
<span class="na">always-on</span> <span class="o">=</span> <span class="s">True</span>
</pre></div>
</div>
<p>Plugins may accept any number of other config values, which may be
booleans, strings, integers or lists. A polite plugin will document
these options somewhere. Plugins that want to make use of nose2’s
<a class="reference external" href="http://sphinx.pocoo.org/">Sphinx</a> extension as detailed in <a class="reference internal" href="dev/documenting_plugins.html"><span class="doc">Documenting plugins</span></a>
<em>must</em> extract all of their config values in their <code class="docutils literal"><span class="pre">__init__</span></code>
methods.</p>
</div>
<div class="section" id="test-runner-tips-and-tweaks">
<h2>Test Runner Tips and Tweaks<a class="headerlink" href="#test-runner-tips-and-tweaks" title="Permalink to this headline">¶</a></h2>
<div class="section" id="running-tests-in-a-single-module">
<h3>Running Tests in a Single Module<a class="headerlink" href="#running-tests-in-a-single-module" title="Permalink to this headline">¶</a></h3>
<p>You can use <code class="docutils literal"><span class="pre">nose2.main</span></code> in the same way that <code class="docutils literal"><span class="pre">unittest.main</span></code> (and
<code class="docutils literal"><span class="pre">unittest2.main</span></code>) have historically worked: to run the tests in a
single module. Just put a block like the following at the end of the
module:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">'__main__'</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">nose2</span>
<span class="n">nose2</span><span class="o">.</span><span class="n">main</span><span class="p">()</span>
</pre></div>
</div>
<p>Then <em>run the module directly</em> – In other words, do not run the
<code class="docutils literal"><span class="pre">nose2</span></code> script.</p>
</div>
<div class="section" id="rolling-your-own-runner">
<h3>Rolling Your Own Runner<a class="headerlink" href="#rolling-your-own-runner" title="Permalink to this headline">¶</a></h3>
<p>You can take more control over the test runner by foregoing the
<code class="docutils literal"><span class="pre">nose2</span></code> script and rolling your own. To do that, you just need to
write a script that calls <code class="docutils literal"><span class="pre">nose2.discover</span></code>, for instance:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">'__main__'</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">nose2</span>
<span class="n">nose2</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span>
</pre></div>
</div>
<p>You can pass several keyword arguments to <code class="docutils literal"><span class="pre">nose2.discover</span></code>, all of
which are detailed in the documentation for
<a class="reference internal" href="dev/main.html#nose2.main.PluggableTestProgram" title="nose2.main.PluggableTestProgram"><code class="xref py py-class docutils literal"><span class="pre">nose2.main.PluggableTestProgram</span></code></a>.</p>
<div class="section" id="altering-the-default-plugin-set">
<h4>Altering the Default Plugin Set<a class="headerlink" href="#altering-the-default-plugin-set" title="Permalink to this headline">¶</a></h4>
<p>To add plugin <em>modules</em> to the list of those automatically loaded, you
can pass a list of module names to add (the <code class="docutils literal"><span class="pre">plugins</span></code>) argument or
exclude (<code class="docutils literal"><span class="pre">excludedPlugins</span></code>). You can also subclass
<a class="reference internal" href="dev/main.html#nose2.main.PluggableTestProgram" title="nose2.main.PluggableTestProgram"><code class="xref py py-class docutils literal"><span class="pre">nose2.main.PluggableTestProgram</span></code></a> and set the class-level
<code class="docutils literal"><span class="pre">defaultPlugins</span></code> and <code class="docutils literal"><span class="pre">excludePlugins</span></code> attributes to alter plugin
loading.</p>
</div>
<div class="section" id="when-loading-plugins-from-modules-is-not-enough">
<h4>When Loading Plugins from Modules is not Enough<a class="headerlink" href="#when-loading-plugins-from-modules-is-not-enough" title="Permalink to this headline">¶</a></h4>
<p><strong>None of which will help</strong> if you need to register a plugin <em>instance</em>
that you’ve loaded yourself. For that, use the <code class="docutils literal"><span class="pre">extraHooks</span></code> keyword
argument to <code class="docutils literal"><span class="pre">nose2.discover</span></code>. Here, you pass in a list of 2-tuples,
each of which contains a hook name and a plugin <em>instance</em> to register
for that hook. This allows you to register plugins that need runtime
configuration that is not easily passed in through normal channels –
and also to register <em>objects that are not nose2 plugins</em> as hook
targets. Here’s a trivial example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">'__main__'</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">nose2</span>
<span class="k">class</span> <span class="nc">Hello</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">startTestRun</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"hello!"</span><span class="p">)</span>
<span class="n">nose2</span><span class="o">.</span><span class="n">discover</span><span class="p">(</span><span class="n">extraHooks</span><span class="o">=</span><span class="p">[(</span><span class="s1">'startTestRun'</span><span class="p">,</span> <span class="n">Hello</span><span class="p">())])</span>
</pre></div>
</div>
<p>This can come in handy when integrating with other systems that expect
you to provide a test runner that they execute, rather than executing
tests yourself (django, for instance).</p>
</div>
</div>
</div>
</div>
</div>
<div class="articleComments">
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="differences.html" class="btn btn-neutral float-right" title="Differences: nose2 vs nose vs unittest2" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="usage.html" class="btn btn-neutral" title="Using nose2" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2018, Jason Pellerin.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'0.6.0',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>
|