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.
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).
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.
Bases: nose.plugins.base.Plugin
Load tests from scripts that may not have a .py extension.
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.
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.
Save the loader.
This instance will be used later by loadTestsFromFile() if necessary.
Load a module from path.
Parameters: |
|
---|
New in version 0.2.0.