From 0676554e68002ce864402d6447b40d9122f4bd61 Mon Sep 17 00:00:00 2001 From: Jordan Adler Date: Fri, 19 Oct 2018 14:05:40 -0700 Subject: [PATCH 1/2] Switch to pytest --- .travis.yml | 4 +--- TESTING.txt | 8 +++---- discover_tests.py | 57 ----------------------------------------------- setup.py | 2 -- tox.ini | 3 ++- 5 files changed, 6 insertions(+), 68 deletions(-) delete mode 100644 discover_tests.py diff --git a/.travis.yml b/.travis.yml index 45c8a1e3..d026a668 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ matrix: sudo: required # required for Python 3.7 (travis-ci/travis-ci#9069) install: - - pip install tox + - pip install tox pytest before_script: # Run flake8 tests only on Python 2.7 and 3.7... @@ -30,7 +30,5 @@ before_script: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics; fi -# command to run tests, e.g. python setup.py test - script: - tox diff --git a/TESTING.txt b/TESTING.txt index 68a1c971..1c29b6a6 100644 --- a/TESTING.txt +++ b/TESTING.txt @@ -1,9 +1,7 @@ Currently the tests are passing on OS X and Linux on Python 2.7 and 3.4. -The test suite can be run either with: +The test suite can be run with: - $ python setup.py test + $ tox -which uses the unittest module's test discovery mechanism, or with: - - $ py.test +which tests the module under a number of different python versions, where available. diff --git a/discover_tests.py b/discover_tests.py deleted file mode 100644 index 1d289418..00000000 --- a/discover_tests.py +++ /dev/null @@ -1,57 +0,0 @@ -""" -Simple auto test discovery. - -From http://stackoverflow.com/a/17004409 -""" -import os -import sys -import unittest - -if not hasattr(unittest.defaultTestLoader, 'discover'): - try: - import unittest2 as unittest - except ImportError: - raise ImportError('The unittest2 module is required to run tests on Python 2.6') - -def additional_tests(): - setup_file = sys.modules['__main__'].__file__ - setup_dir = os.path.abspath(os.path.dirname(setup_file)) - test_dir = os.path.join(setup_dir, 'tests') - test_suite = unittest.defaultTestLoader.discover(test_dir) - blacklist = [] - if '/home/travis' in __file__: - # Skip some tests that fail on travis-ci - blacklist.append('test_command') - return exclude_tests(test_suite, blacklist) - - -class SkipCase(unittest.TestCase): - def skeleton_run_test(self): - raise unittest.SkipTest("Test fails spuriously on travis-ci") - - -def exclude_tests(suite, blacklist): - """ - Example: - - blacklist = [ - 'test_some_test_that_should_be_skipped', - 'test_another_test_that_should_be_skipped' - ] - """ - new_suite = unittest.TestSuite() - - for test_group in suite._tests: - for test in test_group: - if not hasattr(test, '_tests'): - # e.g. ModuleImportFailure - new_suite.addTest(test) - continue - for subtest in test._tests: - method = subtest._testMethodName - if method in blacklist: - setattr(test, - method, - getattr(SkipCase(), 'skeleton_run_test')) - new_suite.addTest(test) - return new_suite diff --git a/setup.py b/setup.py index 62644437..05ee3243 100755 --- a/setup.py +++ b/setup.py @@ -78,7 +78,6 @@ 'LICENSE.txt', 'futurize.py', 'pasteurize.py', - 'discover_tests.py', 'check_rst.sh', 'TESTING.txt', ], @@ -177,6 +176,5 @@ include_package_data=True, python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", classifiers=CLASSIFIERS, - test_suite = "discover_tests", **setup_kwds ) diff --git a/tox.ini b/tox.ini index 1f0f1705..96f949a3 100644 --- a/tox.ini +++ b/tox.ini @@ -2,4 +2,5 @@ envlist = py27,py34,py35,py36,py37 [testenv] -commands = python setup.py test +deps = pytest +commands = pytest {posargs} From 9803efc7f5f5e2090d19d5b3346419bb9e815bd3 Mon Sep 17 00:00:00 2001 From: Jordan Adler Date: Fri, 19 Oct 2018 14:10:51 -0700 Subject: [PATCH 2/2] Remove unnecessary pytest dep for travis as tox will take care of it --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d026a668..684ac64a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ matrix: sudo: required # required for Python 3.7 (travis-ci/travis-ci#9069) install: - - pip install tox pytest + - pip install tox before_script: # Run flake8 tests only on Python 2.7 and 3.7...