diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-11-20 17:47:23 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-11-20 17:47:23 -0500 |
commit | 9750b2d6786339dc8230e0ff745bd3f81ecf5054 (patch) | |
tree | 62fb72703aad000a36f1c573a0a4ef9b2116d2ca | |
parent | c4a8b1a04196a7ef5b3025bb6484b81038ed7c6d (diff) | |
download | python-coveragepy-9750b2d6786339dc8230e0ff745bd3f81ecf5054.tar.gz |
No more nose, use pytest as test runner
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | doc/contributing.rst | 2 | ||||
-rw-r--r-- | igor.py | 31 | ||||
-rw-r--r-- | requirements/dev.pip | 1 | ||||
-rw-r--r-- | tests/__init__.py | 5 | ||||
-rw-r--r-- | tests/test_farm.py | 17 | ||||
-rw-r--r-- | tox.ini | 1 |
7 files changed, 25 insertions, 34 deletions
@@ -19,7 +19,7 @@ clean: -rm -rf __pycache__ */__pycache__ */*/__pycache__ */*/*/__pycache__ */*/*/*/__pycache__ */*/*/*/*/__pycache__ -rm -f coverage/*,cover -rm -f MANIFEST - -rm -f .coverage .coverage.* coverage.xml .metacov* .noseids + -rm -f .coverage .coverage.* coverage.xml .metacov* -rm -f tests/zipmods.zip -rm -rf tests/eggsrc/build tests/eggsrc/dist tests/eggsrc/*.egg-info -rm -f setuptools-*.egg distribute-*.egg distribute-*.tar.gz diff --git a/doc/contributing.rst b/doc/contributing.rst index f631dd2..a51f5fd 100644 --- a/doc/contributing.rst +++ b/doc/contributing.rst @@ -42,6 +42,8 @@ these steps: #. (Optional, but recommended) Create a virtualenv to work in, and activate it. +.. mkvirtualenv -p /usr/local/pythonz/pythons/CPython-2.7.11/bin/python coverage + #. Clone the repo:: $ hg clone https://bitbucket.org/ned/coveragepy @@ -20,6 +20,7 @@ import textwrap import warnings import zipfile +import pytest # We want to see all warnings while we are running tests. But we also need to # disable warnings for some of the more complex setting up of tests. @@ -94,24 +95,15 @@ def should_skip(tracer): return msg -def run_tests(tracer, *nose_args): +def run_tests(tracer, *runner_args): """The actual running of tests.""" - with ignore_warnings(): - import nose.core - if 'COVERAGE_TESTING' not in os.environ: os.environ['COVERAGE_TESTING'] = "True" print_banner(label_for_tracer(tracer)) - if 'COVERAGE_PYTEST' in os.environ: - import pytest - runner_args = list(nose_args) - return pytest.main(runner_args) - else: - nose_args = ["nosetests"] + list(nose_args) - return nose.core.main(argv=nose_args) + return pytest.main(list(runner_args)) -def run_tests_with_coverage(tracer, *nose_args): +def run_tests_with_coverage(tracer, *runner_args): """Run tests, but with coverage.""" # Need to define this early enough that the first import of env.py sees it. @@ -122,8 +114,7 @@ def run_tests_with_coverage(tracer, *nose_args): # Create the .pth file that will let us measure coverage in sub-processes. # The .pth file seems to have to be alphabetically after easy-install.pth # or the sys.path entries aren't created right? - import nose - pth_dir = os.path.dirname(os.path.dirname(nose.__file__)) + pth_dir = os.path.dirname(pytest.__file__) pth_path = os.path.join(pth_dir, "zzz_metacov.pth") with open(pth_path, "w") as pth_file: pth_file.write("import coverage; coverage.process_startup()\n") @@ -162,9 +153,9 @@ def run_tests_with_coverage(tracer, *nose_args): import coverage # pylint: disable=reimported sys.modules.update(covmods) - # Run nosetests, with the arguments from our command line. + # Run tests, with the arguments from our command line. try: - run_tests(tracer, *nose_args) + run_tests(tracer, *runner_args) except SystemExit: # nose3 seems to raise SystemExit, not sure why? pass @@ -189,8 +180,8 @@ def do_combine_html(): cov.xml_report() -def do_test_with_tracer(tracer, *noseargs): - """Run nosetests with a particular tracer.""" +def do_test_with_tracer(tracer, *runner_args): + """Run tests with a particular tracer.""" # If we should skip these tests, skip them. skip_msg = should_skip(tracer) if skip_msg: @@ -199,9 +190,9 @@ def do_test_with_tracer(tracer, *noseargs): os.environ["COVERAGE_TEST_TRACER"] = tracer if os.environ.get("COVERAGE_COVERAGE", ""): - return run_tests_with_coverage(tracer, *noseargs) + return run_tests_with_coverage(tracer, *runner_args) else: - return run_tests(tracer, *noseargs) + return run_tests(tracer, *runner_args) def do_zip_mods(): diff --git a/requirements/dev.pip b/requirements/dev.pip index 29be753..9da0d69 100644 --- a/requirements/dev.pip +++ b/requirements/dev.pip @@ -5,7 +5,6 @@ # https://requires.io/github/nedbat/coveragepy/requirements/ # PyPI requirements for running tests. -nose==1.3.7 -r tox.pip # for linting. diff --git a/tests/__init__.py b/tests/__init__.py index 5a0e30f..1ff1e1b 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1,4 @@ -"""Automated tests. Run with nosetests.""" +# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt + +"""Automated tests. Run with pytest.""" diff --git a/tests/test_farm.py b/tests/test_farm.py index ae9e915..1a67e36 100644 --- a/tests/test_farm.py +++ b/tests/test_farm.py @@ -1,7 +1,7 @@ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt -"""Run tests in the farm sub-directory. Designed for nose.""" +"""Run tests in the farm sub-directory. Designed for pytest.""" import difflib import filecmp @@ -13,8 +13,6 @@ import shutil import sys import unittest -from nose.plugins.skip import SkipTest - from unittest_mixins import ModuleAwareMixin, SysPathAwareMixin, change_dir, saved_sys_path from tests.helpers import run_command from tests.backtest import execfile # pylint: disable=redefined-builtin @@ -51,8 +49,7 @@ class FarmTestCase(ModuleAwareMixin, SysPathAwareMixin, unittest.TestCase): cleaning-only, or run and leave the results for debugging). This class is a unittest.TestCase so that we can use behavior-modifying - mixins, but it's only useful as a nose test function. Yes, this is - confusing. + mixins, but it's only useful as a test function. Yes, this is confusing. """ @@ -75,13 +72,13 @@ class FarmTestCase(ModuleAwareMixin, SysPathAwareMixin, unittest.TestCase): self.ok = True def setUp(self): - """Test set up, run by nose before __call__.""" + """Test set up, run by the test runner before __call__.""" super(FarmTestCase, self).setUp() # Modules should be importable from the current directory. sys.path.insert(0, '') def tearDown(self): - """Test tear down, run by nose after __call__.""" + """Test tear down, run by the test runner after __call__.""" # Make sure the test is cleaned up, unless we never want to, or if the # test failed. if not self.dont_clean and self.ok: # pragma: part covered @@ -90,8 +87,8 @@ class FarmTestCase(ModuleAwareMixin, SysPathAwareMixin, unittest.TestCase): super(FarmTestCase, self).tearDown() - # This object will be run by nose via the __call__ method, and nose - # doesn't do cleanups in that case. Do them now. + # This object will be run via the __call__ method, and test runners + # don't do cleanups in that case. Do them now. self.doCleanups() def runTest(self): @@ -345,7 +342,7 @@ def clean(cleandir): def skip(msg=None): """Skip the current test.""" - raise SkipTest(msg) + raise unittest.SkipTest(msg) # Helpers @@ -12,7 +12,6 @@ deps = # https://requires.io/github/nedbat/coveragepy/requirements/ git+https://github.com/nedbat/pytest.git@bug2038#egg=pytest==0.0 pip==8.1.2 - nose==1.3.7 mock==2.0.0 PyContracts==1.7.9 unittest-mixins==1.1.1 |