Skip to content

Commit

Permalink
Clean up test runner
Browse files Browse the repository at this point in the history
Test code doesn't need to manually construct a TestSuite and a
TextTestRunner, the unittest module has a discovery function that does
all this for you.

Delete all of the manual logic from tests.py, replace it with the two
lines to bring in the doctest unit tests, and update the makefile to
run the unittest discovery.
  • Loading branch information
rossburton committed Mar 16, 2023
1 parent a95c26f commit 04a864f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ help:
@echo

test:
python tests.py
python -munittest

coverage:
coverage run --source=jsonpointer tests.py
Expand Down
24 changes: 4 additions & 20 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import unittest
import sys
import copy
import jsonpointer
from jsonpointer import resolve_pointer, EndOfList, JsonPointerException, \
JsonPointer, set_pointer

Expand Down Expand Up @@ -410,23 +411,6 @@ def test_mock_dict_raises_key_error(self):
self.assertRaises(JsonPointerException, resolve_pointer, doc, '/root/1/2/3/4')



suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(SpecificationTests))
suite.addTest(unittest.makeSuite(ComparisonTests))
suite.addTest(unittest.makeSuite(WrongInputTests))
suite.addTest(unittest.makeSuite(ToLastTests))
suite.addTest(unittest.makeSuite(SetTests))
suite.addTest(unittest.makeSuite(AltTypesTests))

modules = ['jsonpointer']

for module in modules:
m = __import__(module, fromlist=[module])
suite.addTest(doctest.DocTestSuite(m))

runner = unittest.TextTestRunner(verbosity=1)
result = runner.run(suite)

if not result.wasSuccessful():
sys.exit(1)
def load_tests(loader, tests, ignore):
tests.addTests(doctest.DocTestSuite(jsonpointer))
return tests

0 comments on commit 04a864f

Please sign in to comment.