scriptloader loads scripts (into nose)

scriptloader is a tiny plugin for the nose testing tool for Python. With scriptloader, you can run nose on files that aren’t usually importable (like scripts without the ‘.py’ extension). Take a look:

$ cat /tmp/tests
import unittest

class TestFoo(unittest.TestCase):

    def test_easy(self):
        self.assertEqual(1 + 1, 2)
$ nosetests  /tmp/tests
E
======================================================================
ERROR: Failure: ValueError (Unable to load tests from file /tmp/tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/will/share/venv/2.6/lib/python2.6/site-packages/nose/loader.py", line 206, in loadTestsFromFile
    % filename)
ValueError: Unable to load tests from file /tmp/tests

----------------------------------------------------------------------
Ran 1 test in 0.003s

FAILED (errors=1)
witten:~ $ nosetests --with-scriptloader /tmp/tests
.
----------------------------------------------------------------------
Ran 1 test in 0.003s

OK

Note

When run with Python interpreters that don’t support sys.dont_write_bytecode (ie, Python versions < 2.6), this plugin may cause a file named like the script under test with a ‘c’ extension to be created as a side effect of testing. See load_source() for more information.

Installing scriptloader

You can install the latest stable version of scriptloader using pip:

$ pip install scriptloader

Public repositories for the project are hosted at github and bitbucket, so you can use either git or Mercurial to get a copy of the project’s code and history:

$ hg clone http://bitbucket.org/wcmaier/scriptloader
$ git clone git://github.com/wcmaier/scriptloader.git

If you notice a problem with scriptloader, please report it using the github issue tracker (or, if you have a fix, send a pull request).

A note about versions

scriptloader is developed along two branches. The first, ‘default’ (or ‘master’ in git) contains new features and possible bugs – this branch is the active development branch. The second, ‘stable’, contains releases both major and minor as well as bugfixes. If you’d like to help improve scriptloader, take a look at default/master. Otherwise, stick with stable.

Guts

class scriptloader.ScriptLoader

Bases: nose.plugins.base.Plugin

Load tests from scripts that may not have a .py extension.

loadTestsFromFile(filename, loader=<function load_source at 0x7e057a74>)

Load tests from filename.

Attempt to load the file using imp.load_source(). If that succeeds, pass the loaded module to the loader loadTestsFromModule(). If the file can’t be loaded, return None so other plugins can try loading it.

loadTestsFromName(name, module=None, discovered=False, addr=None, loader=<function load_source at 0x7e057a74>)

Load tests from the entity with the given name.

If name is a filename, attempt to load it using imp.load_source(). If that succeeds, search for a matching name in the loaded module.

prepareTestLoader(loader)

Save the loader.

This instance will be used later by loadTestsFromFile() if necessary.

scriptloader.load_source(name, path, bytecode=False)

Load a module from path.

Parameters:

New in version 0.2.0.

Table Of Contents

This Page