From 400491ca6582bd70f18686b0f954cb32fdee26e0 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 00:12:53 -0700 Subject: Update coveragerc to add an additional path --- .coveragerc | 1 + 1 file changed, 1 insertion(+) diff --git a/.coveragerc b/.coveragerc index d0a1fd54a..4009892ea 100644 --- a/.coveragerc +++ b/.coveragerc @@ -6,6 +6,7 @@ source = [paths] source = src/pyramid + */src/pyramid */site-packages/pyramid [report] -- cgit v1.2.3 From a4d35b2cd24731036c381248c3f0eb475dcd2f8f Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 00:13:20 -0700 Subject: Add configuration for pytest --- setup.cfg | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index 756233bd0..a7a5ff4fe 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,10 +1,6 @@ [easy_install] zip_ok = false -[nosetests] -match = ^test -nocapture = 1 - [aliases] dev = develop easy_install pyramid[testing] docs = develop easy_install pyramid[docs] @@ -21,3 +17,9 @@ ignore = ignore-default-rules = true ignore-bad-ideas = tests/pkgs/localeapp/**/*.mo + +[tool:pytest] +python_files = test_*.py +testpaths = + tests +addopts = -W always --cov -- cgit v1.2.3 From cb2be5f16dad334e4718852f27c6408c3d2d6d4a Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 00:13:41 -0700 Subject: Add testing requires for pytest/pytest-cov --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2487d0952..1a334efe2 100644 --- a/setup.py +++ b/setup.py @@ -51,7 +51,7 @@ docs_extras = [ 'sphinxcontrib-autoprogram', ] -testing_extras = tests_require + ['coverage', 'nose'] +testing_extras = tests_require + ['coverage', 'pytest', 'pytest-cov'] branch_version = ".".join(VERSION.split(".")[:2]) -- cgit v1.2.3 From 66fc1ccc27b445dfadf16b09a7e838f6aac21899 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 00:14:03 -0700 Subject: Update tox.ini to run pytest instead --- tox.ini | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tox.ini b/tox.ini index 74f5cfbbd..45e786684 100644 --- a/tox.ini +++ b/tox.ini @@ -2,16 +2,14 @@ envlist = lint, py35,py36,py37,py38,pypy3, - docs,py36-cover,coverage, + docs,coverage, [testenv] commands = - cover: coverage run \ - {envbindir}/nosetests --with-xunit --xunit-file=nosetests-{envname}.xml {posargs:} + python --version + pytest {posargs:} extras = testing -deps = - cover: coverage setenv = COVERAGE_FILE=.coverage.{envname} -- cgit v1.2.3 From 72eca2f8e82f1af20e433218719d99e7627d5650 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 00:14:30 -0700 Subject: Fix tests that depend on the test runner --- tests/test_path.py | 4 ++-- tests/test_util.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_path.py b/tests/test_path.py index 384460fb1..c9cfde2b6 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -101,10 +101,10 @@ class TestCallerPackage(unittest.TestCase): self.assertEqual(result, tests) def test_it_level_3(self): - import unittest + import _pytest result = self._callFUT(3) - self.assertEqual(result, unittest) + self.assertEqual(result, _pytest) def test_it_package(self): import tests diff --git a/tests/test_util.py b/tests/test_util.py index 93493c683..f79cdeb85 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -492,8 +492,7 @@ class Test_object_description(unittest.TestCase): def test_method(self): self.assertEqual( self._callFUT(self.test_method), - 'method test_method of class tests.test_util.' - 'Test_object_description', + 'function tests.test_util.test_method', ) def test_class(self): -- cgit v1.2.3 From b6df90d05262dc24a91f7edd1e477cf7e8a9fff6 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 01:03:03 -0700 Subject: Cleanup nosetest mentions in docs Co-authored-by: Steve Piercy --- HACKING.txt | 69 +++++++++++++++++++------------------- docs/typographical-conventions.rst | 9 ++--- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/HACKING.txt b/HACKING.txt index 87c96aef1..7e4969990 100644 --- a/HACKING.txt +++ b/HACKING.txt @@ -8,7 +8,7 @@ Using a Development Checkout ---------------------------- You will have to create a development environment to hack on Pyramid, using a -Pyramid checkout. We use `tox` to run tests, run test coverage, and build +Pyramid checkout. We use `tox` to run tests, run test coverage, and build documentation. tox docs: https://tox.readthedocs.io/en/latest/ @@ -25,6 +25,22 @@ tox on PyPI: https://pypi.org/project/tox/ Alternatively, create a writeable fork on GitHub and clone it. +- Make sure that `tox` is installed, either in your path, or locally. Examples + below assume that `tox` was installed with: + + $ pip3 install --user tox + $ export TOX=$(python3 -c 'import site; print(site.USER_BASE + "/bin")')/tox + + Feel free to use whatever is your favorite method for installation. One + popular method uses `pipx` (https://github.com/pipxproject/pipx). + + Before you file a pull request, we recommend that you run your proposed + change through `tox`. `tox` will fully validate that all tests work, all + supported formats of documentation will build and their doctests pass, and + test coverage is 100%, across all supported versions of Python. `tox` will + only run builds for Python versions that you have installed and made + available to `tox`. Setting up that environment is outside the scope of this + document. Adding Features --------------- @@ -51,58 +67,43 @@ Coding Style - Pyramid uses Black (https://pypi.org/project/black/) and isort (https://pypi.org/project/isort/) for code formatting style. To run formatters: - $ tox -e format + $ $TOX -e format Running Tests ------------- -- The `tox.ini` uses `nose` and `coverage`. As such `tox` may be used +- The `tox.ini` uses `pytest` and `coverage`. As such `tox` may be used to run groups of tests or only a specific version of Python. For example, the - following command will run tests on Python 3.7 only without coverage: + following command will run tests on the same version of Python that `tox` is + installed with: - $ tox -e py37 + $ $TOX -e py - This command will run tests on the latest version of Python 3 with coverage. + To run `tox` for Python 3.8 explicitly, you may use: - $ tox -e py36-cover,coverage + $ $TOX -e py38 -- To run individual tests (i.e., during development), you can use `nosetests` +- To run individual tests (i.e., during development), you can use `pytest` syntax as follows, where `$VENV` is an environment variable set to the path to your virtual environment: # run a single test - $ $VENV/bin/nosetests tests.test_module:ClassName.test_mytestname + $ $TOX -e py -- --no-cov tests/test_httpexceptions.py::TestHTTPMethodNotAllowed::test_it_with_default_body_tmpl # run all tests in a class - $ $VENV/bin/nosetests tests.test_module:ClassName - - Optionally you can install a nose plugin `nose-selecttests` to run specific - tests. - https://pypi.org/project/nose-selecttests/ - For example, use a regular expression with the `-t` parameter to run tests. - - # run a single test - $ $VENV/bin/nosetests -t test_mytestname - -- The tests can also be run using `pytest`. - https://docs.pytest.org/en/latest/ - This is intended as a convenience for people who prefer `pytest`. Run the - tests like so: - - $ $VENV/bin/pip install pytest - $ $VENV/bin/pytest --strict pyramid/ tests/ + $ $TOX -e py -- --no-cov tests/test_httpexceptions.py::TestHTTPMethodNotAllowed - To run individual tests (i.e., during development), see "pytest usage - - Specifying tests / selecting tests": +- For more information on how to use pytest, please refer to the pytest + documentation for selecting tests: https://docs.pytest.org/en/latest/usage.html#specifying-tests-selecting-tests Test Coverage ------------- -- The codebase *must* have 100% test statement coverage after each commit. You - can test coverage via `tox -epy3-cover,coverage`. +- The codebase *must* have 100% test statement coverage after each commit. You + can test coverage via `tox -e py38`. Documentation Coverage and Building HTML Documentation @@ -111,11 +112,11 @@ Documentation Coverage and Building HTML Documentation If you fix a bug, and the bug requires an API or behavior modification, all documentation in this package which references that API or behavior must be changed to reflect the bug fix, ideally in the same commit that fixes the bug -or adds the feature. To build and review docs, use the following steps. +or adds the feature. To build and review docs, use the following steps. 1. In the main Pyramid checkout directory, run `tox -e docs`: - $ tox -e docs + $ $TOX -e docs 2. Open the `.tox/docs/html/index.html` file to see the resulting HTML rendering. @@ -125,6 +126,6 @@ Change Log ---------- - Feature additions and bugfixes must be added to the `CHANGES.rst` - file in the prevailing style. Changelog entries should be long and - descriptive, not cryptic. Other developers should be able to know + file in the prevailing style. Changelog entries should be long and + descriptive, not cryptic. Other developers should be able to know what your changelog entry means. diff --git a/docs/typographical-conventions.rst b/docs/typographical-conventions.rst index 7f052cbc8..0a9c194e4 100644 --- a/docs/typographical-conventions.rst +++ b/docs/typographical-conventions.rst @@ -98,10 +98,11 @@ ini: .. code-block:: ini - [nosetests] - match=^test - where=pyramid - nocapture=1 + [tool:pytest] + python_files = test_*.py + testpaths = + tests + addopts = -W always --cov Interactive Python: -- cgit v1.2.3 From 57687face8ec3a912d6d886b8b2bcf27a97c82d0 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 23:23:22 -0700 Subject: Disable coverage by default Use a special py38-cover testenv in tox to re-enable coverage reporting. --- .travis.yml | 4 ++-- setup.cfg | 2 +- tox.ini | 9 ++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c762c085b..57c8b935d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,8 @@ matrix: env: TOXENV=py36 - python: pypy3 env: TOXENV=pypy3 - - python: 3.6 - env: TOXENV=py36-cover,coverage + - python: 3.8 + env: TOXENV=py38-cover,coverage - python: 3.6 env: TOXENV=docs - python: 3.6 diff --git a/setup.cfg b/setup.cfg index a7a5ff4fe..83f985f93 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,4 +22,4 @@ ignore-bad-ideas = python_files = test_*.py testpaths = tests -addopts = -W always --cov +addopts = -W always diff --git a/tox.ini b/tox.ini index 45e786684..91baa42db 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,8 @@ envlist = lint, py35,py36,py37,py38,pypy3, - docs,coverage, + py38-cover,coverage, + docs [testenv] commands = @@ -13,6 +14,11 @@ extras = setenv = COVERAGE_FILE=.coverage.{envname} +[testenv:py38-cover] +commands = + python --version + pytest --cov {posargs:} + [testenv:lint] skip_install = true commands = @@ -52,6 +58,7 @@ deps = coverage setenv = COVERAGE_FILE=.coverage +depends = py38-cover [testenv:format] skip_install = true -- cgit v1.2.3