summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2015-07-16 13:40:07 +1200
committerRobert Collins <robertc@robertcollins.net>2015-07-16 13:40:07 +1200
commit8dac7fea3346646cb5b00234a68992e2b9b872a0 (patch)
treef0078f1629604b14cd6ff6263dc888d94aee51aa
parent2a07f0eecbd71c8bd538c60edde6e8056282b312 (diff)
downloadtestrepository-8dac7fea3346646cb5b00234a68992e2b9b872a0.tar.gz
Use the newfangled test discovery feature.
I've checked that this generates the same number of tests.
-rw-r--r--.testr.conf2
-rw-r--r--testrepository/tests/__init__.py36
-rw-r--r--testrepository/tests/arguments/__init__.py14
-rw-r--r--testrepository/tests/commands/__init__.py21
-rw-r--r--testrepository/tests/repository/__init__.py11
-rw-r--r--testrepository/tests/ui/__init__.py12
-rw-r--r--testrepository/tests/ui/test_cli.py2
7 files changed, 9 insertions, 89 deletions
diff --git a/.testr.conf b/.testr.conf
index 8cd68fb..2939b31 100644
--- a/.testr.conf
+++ b/.testr.conf
@@ -1,5 +1,5 @@
[DEFAULT]
-test_command=${PYTHON:-python} -m subunit.run $LISTOPT $IDOPTION testrepository.tests.test_suite
+test_command=${PYTHON:-python} -m subunit.run discover $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list
;filter_tags=worker-0
diff --git a/testrepository/tests/__init__.py b/testrepository/tests/__init__.py
index d6f38dc..7ebb345 100644
--- a/testrepository/tests/__init__.py
+++ b/testrepository/tests/__init__.py
@@ -14,7 +14,7 @@
"""The testrepository tests and test only code."""
-import unittest
+import os
import testresources
from testscenarios import generate_scenarios
@@ -54,33 +54,11 @@ class StubTestCommand:
return self.filter_tags
-def test_suite():
- packages = [
- 'arguments',
- 'commands',
- 'repository',
- 'ui',
- ]
- names = [
- 'arguments',
- 'commands',
- 'matchers',
- 'monkeypatch',
- 'repository',
- 'results',
- 'setup',
- 'stubpackage',
- 'testcommand',
- 'testr',
- 'ui',
- ]
- module_names = ['testrepository.tests.test_' + name for name in names]
- loader = unittest.TestLoader()
- suite = loader.loadTestsFromNames(module_names)
+def load_tests(loader, standard_tests, pattern):
+ # top level directory cached on loader instance
+ this_dir = os.path.dirname(__file__)
+ package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
result = testresources.OptimisingTestSuite()
- result.addTests(generate_scenarios(suite))
- for pkgname in packages:
- pkg = __import__('testrepository.tests.' + pkgname, globals(),
- locals(), ['test_suite'])
- result.addTests(generate_scenarios(pkg.test_suite()))
+ result.addTests(generate_scenarios(standard_tests))
+ result.addTests(generate_scenarios(package_tests))
return result
diff --git a/testrepository/tests/arguments/__init__.py b/testrepository/tests/arguments/__init__.py
index 479c9ca..cf72b2d 100644
--- a/testrepository/tests/arguments/__init__.py
+++ b/testrepository/tests/arguments/__init__.py
@@ -13,17 +13,3 @@
# limitations under that license.
"""Tests for individual arguments."""
-
-import unittest
-
-def test_suite():
- names = [
- 'command',
- 'doubledash',
- 'path',
- 'string',
- ]
- module_names = ['testrepository.tests.arguments.test_' + name for name in
- names]
- loader = unittest.TestLoader()
- return loader.loadTestsFromNames(module_names)
diff --git a/testrepository/tests/commands/__init__.py b/testrepository/tests/commands/__init__.py
index e69418a..f7e36ee 100644
--- a/testrepository/tests/commands/__init__.py
+++ b/testrepository/tests/commands/__init__.py
@@ -13,24 +13,3 @@
# limitations under that license.
"""Tests for commands."""
-
-import unittest
-
-def test_suite():
- names = [
- 'commands',
- 'failing',
- 'help',
- 'init',
- 'last',
- 'list_tests',
- 'load',
- 'quickstart',
- 'run',
- 'slowest',
- 'stats',
- ]
- module_names = ['testrepository.tests.commands.test_' + name for name in
- names]
- loader = unittest.TestLoader()
- return loader.loadTestsFromNames(module_names)
diff --git a/testrepository/tests/repository/__init__.py b/testrepository/tests/repository/__init__.py
index 8d9ba38..70f8249 100644
--- a/testrepository/tests/repository/__init__.py
+++ b/testrepository/tests/repository/__init__.py
@@ -13,14 +13,3 @@
# limitations under that license.
"""Tests for specific repository types."""
-
-import unittest
-
-def test_suite():
- names = [
- 'file',
- ]
- module_names = ['testrepository.tests.repository.test_' + name for name in
- names]
- loader = unittest.TestLoader()
- return loader.loadTestsFromNames(module_names)
diff --git a/testrepository/tests/ui/__init__.py b/testrepository/tests/ui/__init__.py
index 234a736..9ddc828 100644
--- a/testrepository/tests/ui/__init__.py
+++ b/testrepository/tests/ui/__init__.py
@@ -13,15 +13,3 @@
# limitations under that license.
"""Tests for ui modules."""
-
-import unittest
-
-def test_suite():
- names = [
- 'cli',
- 'decorator',
- ]
- module_names = ['testrepository.tests.ui.test_' + name for name in
- names]
- loader = unittest.TestLoader()
- return loader.loadTestsFromNames(module_names)
diff --git a/testrepository/tests/ui/test_cli.py b/testrepository/tests/ui/test_cli.py
index e1f9b44..198865d 100644
--- a/testrepository/tests/ui/test_cli.py
+++ b/testrepository/tests/ui/test_cli.py
@@ -271,7 +271,7 @@ AssertionError: quux...
else:
self.fail('ui.set_command did not raise')
self.assertThat(bytestream.getvalue().decode('utf8'),
- DocTestMatches("""Usage: run.py bar [options] foo
+ DocTestMatches("""Usage: ... bar [options] foo
...
A command that can be run...
...