[RFC/MERGE](0.17) Auto load tests

John Arbash Meinel john at arbash-meinel.com
Sat Apr 28 00:08:32 BST 2007

The attached bundle changes the test loading infrastructure so that we
load based on filenames and .test_suite().

Basically, anything underneath bzrlib/tests/ that is a package
(directory with __init__.py) should implement test_suite() and all files
should be named test*.py.

If we satisfy those 2 constraints, the tests will be automatically found
and loaded at runtime. No more needing to update lists everytime we add
a new test.

It did require moving some of the adapted tests into their own submodule
(test_transport_implementations.py and blackbox.test_non_ascii.py). But
that should have been done anyway.

Mostly this just makes it easier to write new tests because you don't
have to worry about adding them to a list of tests. (It also helps
prevent conflicts when merging.)

Unfortunately the diffstat shows a slight increase, but all of this is
due to the tests for the auto loading functionality:
 TestUtil.py                                    |   92 ++++++++-
 __init__.py                                    |  180 +++--------------
 blackbox/__init__.py                           |   99 ---------
 blackbox/encoding_tests/__init__.py            |   27 ++
 blackbox/test_cat.py                           |    2
 branch_implementations/__init__.py             |   37 ---
 bzrdir_implementations/__init__.py             |   20 -
 interrepository_implementations/__init__.py    |   14 -
 intertree_implementations/__init__.py          |   17 -
 interversionedfile_implementations/__init__.py |   13 -
 per_lock/__init__.py                           |    9
 repository_implementations/__init__.py         |   26 --
 revisionstore_implementations/__init__.py      |   13 -
 test_test_util.py                              |  254
 transport_implementations/__init__.py          |   27 ++
 tree_implementations/__init__.py               |   18 -
 workingtree_implementations/__init__.py        |   48 ----
 17 files changed, 479 insertions(+), 417 deletions(-)

I also added a helper which makes implementing "test_suite()" almost
trivial in most cases.

The one reason this isn't a strict [MERGE] is because it won't work on
the python all-in-one bundle, because we can't call os.listdir() there.
(because it is in a zipfile). So I need to work out how to detect when
we are in a zipfile, and how to list the files in a given directory.

However, everything is going through a small set of functions, so I
expect it to be fairly easy.

If people prefer alternate function names, etc, I would be happy to
oblige. Or if 'load_and_adapt_modules' should be part of TestLoader
instead of a separate function.

Mostly I'm looking for feedback. I wanted to implement this for a plugin
I was writing, because I was getting tired of manually tracking
filenames. (Also with plugins you have to be careful about your python
path, because you are actually loaded as bzrlib.plugins.PLUGIN.tests not

I also verified at every step that we had the same number of tests being
run. On my machine (with the specific plugins I have) there are 6843
tests being run.

Actually, the new "bzr selftest --list" was extremely helpful in making
sure that all tests were still getting loaded.


PS> The autoloader was actually written in TDD fashion, but those
commits are missing because I was doing it in my plugin.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test_autoloader.patch
Url: https://lists.ubuntu.com/archives/bazaar/attachments/20070427/8675ccac/attachment-0001.diff 

More information about the bazaar mailing list