diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..772866d2 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,12 @@ +[paths] +source = src + +[run] +branch = True +source = src +parallel = true + +[report] +show_missing = true +precision = 2 +omit = *migrations* diff --git a/.gitignore b/.gitignore index 0fbfbd25..01f10962 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,60 @@ -.tox/ -*.egg-info/ +*.py[cod] + +# C extensions +*.so + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg +lib +lib64 +venv*/ +pyvenv*/ + +# Installer logs +pip-log.txt + +# Unit test / coverage reports .coverage +.tox .coverage.* -*.pyc \ No newline at end of file +nosetests.xml +htmlcov + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject +.idea +*.iml +*.komodoproject + +# Complexity +output/*.html +output/*/index.html + +# Sphinx +docs/_build + +.DS_Store +*~ +.*.sw[po] +.build +.ve +.env +.cache +.pytest +.bootstrap +*.bak diff --git a/.travis.yml b/.travis.yml index f09d0e10..1224b274 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,45 +1,33 @@ language: python - python: 2.7 - -env: - - CWD=. TOX_ENV=flake8 - - - CWD=pytest-cov TOX_ENV=pypy COV_CORE_DEP=../cov-core - - CWD=pytest-cov TOX_ENV=pypy3 COV_CORE_DEP=../cov-core - - CWD=pytest-cov TOX_ENV=py26 COV_CORE_DEP=../cov-core - - CWD=pytest-cov TOX_ENV=py27 COV_CORE_DEP=../cov-core - - CWD=pytest-cov TOX_ENV=py32 COV_CORE_DEP=../cov-core - - CWD=pytest-cov TOX_ENV=py33 COV_CORE_DEP=../cov-core - - CWD=pytest-cov TOX_ENV=py34 COV_CORE_DEP=../cov-core - - - CWD=pytest-cov TOX_ENV=pypy COV_CORE_DEP=cov-core - - CWD=pytest-cov TOX_ENV=pypy3 COV_CORE_DEP=cov-core - - CWD=pytest-cov TOX_ENV=py26 COV_CORE_DEP=cov-core - - CWD=pytest-cov TOX_ENV=py27 COV_CORE_DEP=cov-core - - CWD=pytest-cov TOX_ENV=py32 COV_CORE_DEP=cov-core - - CWD=pytest-cov TOX_ENV=py33 COV_CORE_DEP=cov-core - - CWD=pytest-cov TOX_ENV=py34 COV_CORE_DEP=cov-core - -matrix: - allow_failures: - - env: CWD=pytest-cov TOX_ENV=pypy COV_CORE_DEP=cov-core - - env: CWD=pytest-cov TOX_ENV=pypy3 COV_CORE_DEP=cov-core - - env: CWD=pytest-cov TOX_ENV=py26 COV_CORE_DEP=cov-core - - env: CWD=pytest-cov TOX_ENV=py27 COV_CORE_DEP=cov-core - - env: CWD=pytest-cov TOX_ENV=py32 COV_CORE_DEP=cov-core - - env: CWD=pytest-cov TOX_ENV=py33 COV_CORE_DEP=cov-core - - env: CWD=pytest-cov TOX_ENV=py34 COV_CORE_DEP=cov-core - sudo: false - +env: + global: + LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so + matrix: + - TOXENV=check + - TOXENV=2.6-37 + - TOXENV=2.7-37 + - TOXENV=3.3-37 + - TOXENV=3.4-37 + - TOXENV=pypy-37 + - TOXENV=2.6-40 + - TOXENV=2.7-40 + - TOXENV=3.3-40 + - TOXENV=3.4-40 + - TOXENV=pypy-40 +before_install: + - python --version + - virtualenv --version + - pip --version + - uname -a + - lsb_release -a install: - pip install tox - script: - - cd $CWD && tox -e $TOX_ENV - + - tox -v notifications: email: on_success: never - on_failure: change + on_failure: always + diff --git a/AUTHORS.rst b/AUTHORS.rst new file mode 100644 index 00000000..f46a017f --- /dev/null +++ b/AUTHORS.rst @@ -0,0 +1,13 @@ +Authors +======= + +* Marc Schlaich - http://www.schlamar.org/ +* Rick van Hattem - http://wol.ph/ +* Buck Evan - https://github.com/bukzor +* Eric Larson - http://larsoner.com/ +* Marc Abramowitz - http://marc-abramowitz.com/ +* Thomas Kluyver - https://github.com/takluyver +* Guillaume Ayoub - http://www.yabz.fr/ +* Federico Ceratto - http://firelet.net/ +* Josh Kalderimis - http://blog.cookiestack.com/ +* Ionel Cristian Mărieș - http://blog.ionelmc.ro diff --git a/CHANGELOG.rst b/CHANGELOG.rst new file mode 100644 index 00000000..8b94fa3d --- /dev/null +++ b/CHANGELOG.rst @@ -0,0 +1,22 @@ +Changelog +========= + +2.0.0 (??????????) +------------------ + +* Added ``--cov-fail-under``, akin to the new ``fail_under`` option in `coverage-4.0` + (automatically activated if there's a ``[report] fail_under = ...`` in ``.coveragerc``). +* Changed ``--cov-report=term`` to automatically upgrade to ``--cov-report=term-missing`` + if there's ``[run] show_missing = True`` in ``.coveragerc``. +* Changed ``--cov`` so it can be used with no path argument (in wich case the source + settings from ``.coveragerc`` will be used instead). +* Fixed `.pth` installation to work in all cases (install, easy_install, wheels, develop etc). +* Fixed `.pth` uninstallation to work for wheel installs. +* Support for coverage 4.0. +* Data file suffixing changed to use coverage's ``data_suffix=True`` option (instead of the + custom suffixing). + +1.8.2 (2014-11-06) +------------------ + +* N/A diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 00000000..91573192 --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,89 @@ +============ +Contributing +============ + +Contributions are welcome, and they are greatly appreciated! Every +little bit helps, and credit will always be given. + +Bug reports +=========== + +When `reporting a bug `_ please include: + + * Your operating system name and version. + * Any details about your local setup that might be helpful in troubleshooting. + * Detailed steps to reproduce the bug. + +Documentation improvements +========================== + +pytest-cov could always use more documentation, whether as part of the +official pytest-cov docs, in docstrings, or even on the web in blog posts, +articles, and such. + +Feature requests and feedback +============================= + +The best way to send feedback is to file an issue at https://github.com/schlamar/pytest-cov/issues. + +If you are proposing a feature: + +* Explain in detail how it would work. +* Keep the scope as narrow as possible, to make it easier to implement. +* Remember that this is a volunteer-driven project, and that contributions are welcome :) + +Development +=========== + +To set up `pytest-cov` for local development: + +1. `Fork pytest-cov on GitHub `_. +2. Clone your fork locally:: + + git clone git@github.com:your_name_here/pytest-cov.git + +3. Create a branch for local development:: + + git checkout -b name-of-your-bugfix-or-feature + + Now you can make your changes locally. + +4. When you're done making changes, run all the checks, doc builder and spell checker with `tox `_ one command:: + + tox + +5. Commit your changes and push your branch to GitHub:: + + git add . + git commit -m "Your detailed description of your changes." + git push origin name-of-your-bugfix-or-feature + +6. Submit a pull request through the GitHub website. + +Pull Request Guidelines +----------------------- + +If you need some code review or feedback while you're developing the code just make the pull request. + +For merging, you should: + +1. Include passing tests (run ``tox``) [1]_. +2. Update documentation when there's new API, functionality etc. +3. Add a note to ``CHANGELOG.rst`` about the changes. +4. Add yourself to ``AUTHORS.rst``. + +.. [1] If you don't have all the necessary python versions available locally you can rely on Travis - it will + `run the tests `_ for each change you add in the pull request. + + It will be slower though ... + +Tips +---- + +To run a subset of tests:: + + tox -e envname -- py.test -k test_myfeature + +To run all the test environments in *parallel* (you need to ``pip install detox``):: + + detox diff --git a/cov-core/LICENSE.txt b/LICENSE similarity index 100% rename from cov-core/LICENSE.txt rename to LICENSE diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..e64932b8 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,21 @@ +graft docs +graft example +graft src +graft ci +graft tests + +include .bumpversion.cfg +include .coveragerc +include .cookiecutterrc +include .isort.cfg +include .pylintrc + +include AUTHORS.rst +include CHANGELOG.rst +include CONTRIBUTING.rst +include LICENSE +include README.rst + +include tox.ini .travis.yml appveyor.yml + +global-exclude *.py[cod] __pycache__ *.so diff --git a/README.rst b/README.rst index 4edbedcb..4e277f4f 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,311 @@ -py-cov -====== +=============================== +pytest-cov +=============================== -Collection of Python coverage projects. +.. list-table:: + :stub-columns: 1 -- pytest-cov -- cov-core + * - docs + - |docs| + * - tests + - | |travis| |appveyor| + * - package + - |version| |downloads| + +.. + |wheel| |supported-versions| |supported-implementations| + +.. |docs| image:: https://readthedocs.org/projects/pytest-cov/badge/?style=flat + :target: https://readthedocs.org/projects/pytest-cov + :alt: Documentation Status + +.. |travis| image:: http://img.shields.io/travis/schlamar/pytest-cov/master.svg?style=flat&label=Travis + :alt: Travis-CI Build Status + :target: https://travis-ci.org/schlamar/pytest-cov + +.. |appveyor| image:: https://img.shields.io/appveyor/ci/schlamar/pytest-cov/master.svg?style=flat&label=AppVeyor + :alt: AppVeyor Build Status + :target: https://ci.appveyor.com/project/schlamar/pytest-cov + +.. |coveralls| image:: http://img.shields.io/coveralls/schlamar/pytest-cov/master.svg?style=flat&label=Coveralls + :alt: Coverage Status + :target: https://coveralls.io/r/schlamar/pytest-cov + +.. |codecov| image:: http://img.shields.io/codecov/c/github/schlamar/pytest-cov/master.svg?style=flat&label=Codecov + :alt: Coverage Status + :target: https://codecov.io/github/schlamar/pytest-cov + +.. |landscape| image:: https://landscape.io/github/schlamar/pytest-cov/master/landscape.svg?style=flat + :target: https://landscape.io/github/schlamar/pytest-cov/master + :alt: Code Quality Status + +.. |version| image:: http://img.shields.io/pypi/v/pytest-cov.svg?style=flat + :alt: PyPI Package latest release + :target: https://pypi.python.org/pypi/pytest-cov + +.. |downloads| image:: http://img.shields.io/pypi/dm/pytest-cov.svg?style=flat + :alt: PyPI Package monthly downloads + :target: https://pypi.python.org/pypi/pytest-cov + +.. |wheel| image:: https://pypip.in/wheel/pytest-cov/badge.svg?style=flat + :alt: PyPI Wheel + :target: https://pypi.python.org/pypi/pytest-cov + +.. |supported-versions| image:: https://pypip.in/py_versions/pytest-cov/badge.svg?style=flat + :alt: Supported versions + :target: https://pypi.python.org/pypi/pytest-cov + +.. |supported-implementations| image:: https://pypip.in/implementation/pytest-cov/badge.svg?style=flat + :alt: Supported imlementations + :target: https://pypi.python.org/pypi/pytest-cov + +.. |scrutinizer| image:: https://img.shields.io/scrutinizer/g/schlamar/pytest-cov/master.svg?style=flat + :alt: Scrutinizer Status + :target: https://scrutinizer-ci.com/g/schlamar/pytest-cov/ + +Pytest plugin for measuring coverage. + +* Free software: MIT license + +This plugin produces coverage reports. It supports centralised testing and distributed testing in +both load and each modes. It also supports coverage of subprocesses. + +All features offered by the coverage package should be available, either through pytest-cov or +through coverage's config file. + + +Installation +============ + +Install with pip:: + + pip install pytest-cov + +For distributed testing support install pytest-xdist:: + + pip install pytest-xdist + +.. NOTE:: + + Ensure you use pip instead of easy_install as the latter does not correctly install the + init_cov_core.pth file needed for subprocess measurement. + + +Uninstallation +============== + +Uninstall with pip:: + + pip uninstall pytest-cov + +Usage +===== + +Centralised Testing +------------------- + +Centralised testing will report on the combined coverage of the main process and all of it's +subprocesses. + +Running centralised testing:: + + py.test --cov=myproj tests/ + +Shows a terminal report:: + + -------------------- coverage: platform linux2, python 2.6.4-final-0 --------------------- + Name Stmts Miss Cover + ---------------------------------------- + myproj/__init__ 2 0 100% + myproj/myproj 257 13 94% + myproj/feature4286 94 7 92% + ---------------------------------------- + TOTAL 353 20 94% + + +Distributed Testing: Load +------------------------- + +Distributed testing with dist mode set to load will report on the combined coverage of all slaves. +The slaves may be spread out over any number of hosts and each slave may be located anywhere on the +file system. Each slave will have it's subprocesses measured. + +Running distributed testing with dist mode set to load:: + + py.test --cov=myproj -n 2 tests/ + +Shows a terminal report:: + + -------------------- coverage: platform linux2, python 2.6.4-final-0 --------------------- + Name Stmts Miss Cover + ---------------------------------------- + myproj/__init__ 2 0 100% + myproj/myproj 257 13 94% + myproj/feature4286 94 7 92% + ---------------------------------------- + TOTAL 353 20 94% + + +Again but spread over different hosts and different directories:: + + py.test --cov=myproj --dist load + --tx ssh=memedough@host1//chdir=testenv1 + --tx ssh=memedough@host2//chdir=/tmp/testenv2//python=/tmp/env1/bin/python + --rsyncdir myproj --rsyncdir tests --rsync examples + tests/ + +Shows a terminal report:: + + -------------------- coverage: platform linux2, python 2.6.4-final-0 --------------------- + Name Stmts Miss Cover + ---------------------------------------- + myproj/__init__ 2 0 100% + myproj/myproj 257 13 94% + myproj/feature4286 94 7 92% + ---------------------------------------- + TOTAL 353 20 94% + + +Distributed Testing: Each +------------------------- + +Distributed testing with dist mode set to each will report on the combined coverage of all slaves. +Since each slave is running all tests this allows generating a combined coverage report for multiple +environments. + +Running distributed testing with dist mode set to each:: + + py.test --cov=myproj --dist each + --tx popen//chdir=/tmp/testenv3//python=/usr/local/python27/bin/python + --tx ssh=memedough@host2//chdir=/tmp/testenv4//python=/tmp/env2/bin/python + --rsyncdir myproj --rsyncdir tests --rsync examples + tests/ + +Shows a terminal report:: + + ---------------------------------------- coverage ---------------------------------------- + platform linux2, python 2.6.5-final-0 + platform linux2, python 2.7.0-final-0 + Name Stmts Miss Cover + ---------------------------------------- + myproj/__init__ 2 0 100% + myproj/myproj 257 13 94% + myproj/feature4286 94 7 92% + ---------------------------------------- + TOTAL 353 20 94% + + +Reporting +========= + +It is possible to generate any combination of the reports for a single test run. + +The available reports are terminal (with or without missing line numbers shown), HTML, XML and +annotated source code. + +The terminal report without line numbers (default):: + + py.test --cov-report term --cov=myproj tests/ + + -------------------- coverage: platform linux2, python 2.6.4-final-0 --------------------- + Name Stmts Miss Cover + ---------------------------------------- + myproj/__init__ 2 0 100% + myproj/myproj 257 13 94% + myproj/feature4286 94 7 92% + ---------------------------------------- + TOTAL 353 20 94% + + +The terminal report with line numbers:: + + py.test --cov-report term-missing --cov=myproj tests/ + + -------------------- coverage: platform linux2, python 2.6.4-final-0 --------------------- + Name Stmts Miss Cover Missing + -------------------------------------------------- + myproj/__init__ 2 0 100% + myproj/myproj 257 13 94% 24-26, 99, 149, 233-236, 297-298, 369-370 + myproj/feature4286 94 7 92% 183-188, 197 + -------------------------------------------------- + TOTAL 353 20 94% + + +These three report options output to files without showing anything on the terminal:: + + py.test --cov-report html + --cov-report xml + --cov-report annotate + --cov=myproj tests/ + +The final report option can also suppress printing to the terminal:: + + py.test --cov-report= --cov=myproj tests/ + +This mode can be especially useful on continuous integration servers, where a coverage file +is needed for subsequent processing, but no local report needs to be viewed. For example, +tests run on Travis-CI could produce a .coverage file for use with Coveralls. + +Coverage Data File +================== + +The data file is erased at the beginning of testing to ensure clean data for each test run. + +The data file is left at the end of testing so that it is possible to use normal coverage tools to +examine it. + + +Coverage Config File +==================== + +This plugin provides a clean minimal set of command line options that are added to pytest. For +further control of coverage use a coverage config file. + +For example if tests are contained within the directory tree being measured the tests may be +excluded if desired by using a .coveragerc file with the omit option set:: + + py.test --cov-config .coveragerc + --cov=myproj + myproj/tests/ + +Where the .coveragerc file contains file globs:: + + [run] + omit = tests/* + +For full details refer to the `coverage config file`_ documentation. + +.. _`coverage config file`: http://nedbatchelder.com/code/coverage/config.html + +Note that this plugin controls some options and setting the option in the config file will have no +effect. These include specifying source to be measured (source option) and all data file handling +(data_file and parallel options). + +Limitations +=========== + +For distributed testing the slaves must have the pytest-cov package installed. This is needed since +the plugin must be registered through setuptools for pytest to start the plugin on the +slave. + +For subprocess measurement environment variables must make it from the main process to the +subprocess. The python used by the subprocess must have pytest-cov installed. The subprocess must +do normal site initialisation so that the environment variables can be detected and coverage +started. + +Acknowledgements +================ + +Whilst this plugin has been built fresh from the ground up it has been influenced by the work done +on pytest-coverage (Ross Lawley, James Mills, Holger Krekel) and nose-cover (Jason Pellerin) which are +other coverage plugins. + +Ned Batchelder for coverage and its ability to combine the coverage results of parallel runs. + +Holger Krekel for pytest with its distributed testing support. + +Jason Pellerin for nose. + +Michael Foord for unittest2. + +No doubt others have contributed to these tools as well. diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..2d5de003 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,96 @@ +version: '{branch}-{build}' +build: off +environment: + global: + WITH_COMPILER: "cmd /E:ON /V:ON /C .\\ci\\appveyor-with-compiler.cmd" + matrix: + - TOXENV: check + PYTHON_HOME: "C:\\Python27" + PYTHON_VERSION: "2.7" + PYTHON_ARCH: "32" + + - TOXENV: "2.7-37" + TOXPYTHON: "C:\\Python27\\python.exe" + WINDOWS_SDK_VERSION: "v7.0" + PYTHON_HOME: "C:\\Python27" + PYTHON_VERSION: "2.7" + PYTHON_ARCH: "32" + - TOXENV: "2.7-37" + TOXPYTHON: "C:\\Python27-x64\\python.exe" + WINDOWS_SDK_VERSION: "v7.0" + PYTHON_HOME: "C:\\Python27-x64" + PYTHON_VERSION: "2.7" + PYTHON_ARCH: "64" + - TOXENV: "3.3-37" + TOXPYTHON: "C:\\Python33\\python.exe" + WINDOWS_SDK_VERSION: "v7.1" + PYTHON_HOME: "C:\\Python33" + PYTHON_VERSION: "3.3" + PYTHON_ARCH: "32" + - TOXENV: "3.3-37" + TOXPYTHON: "C:\\Python33-x64\\python.exe" + WINDOWS_SDK_VERSION: "v7.1" + PYTHON_HOME: "C:\\Python33-x64" + PYTHON_VERSION: "3.3" + PYTHON_ARCH: "64" + - TOXENV: "3.4-37" + TOXPYTHON: "C:\\Python34\\python.exe" + WINDOWS_SDK_VERSION: "v7.1" + PYTHON_HOME: "C:\\Python34" + PYTHON_VERSION: "3.4" + PYTHON_ARCH: "32" + - TOXENV: "3.4-37" + TOXPYTHON: "C:\\Python34-x64\\python.exe" + WINDOWS_SDK_VERSION: "v7.1" + PYTHON_HOME: "C:\\Python34-x64" + PYTHON_VERSION: "3.4" + PYTHON_ARCH: "64" + + - TOXENV: "2.7-40" + TOXPYTHON: "C:\\Python27\\python.exe" + WINDOWS_SDK_VERSION: "v7.0" + PYTHON_HOME: "C:\\Python27" + PYTHON_VERSION: "2.7" + PYTHON_ARCH: "32" + - TOXENV: "2.7-40" + TOXPYTHON: "C:\\Python27-x64\\python.exe" + WINDOWS_SDK_VERSION: "v7.0" + PYTHON_HOME: "C:\\Python27-x64" + PYTHON_VERSION: "2.7" + PYTHON_ARCH: "64" + - TOXENV: "3.3-40" + TOXPYTHON: "C:\\Python33\\python.exe" + WINDOWS_SDK_VERSION: "v7.1" + PYTHON_HOME: "C:\\Python33" + PYTHON_VERSION: "3.3" + PYTHON_ARCH: "32" + - TOXENV: "3.3-40" + TOXPYTHON: "C:\\Python33-x64\\python.exe" + WINDOWS_SDK_VERSION: "v7.1" + PYTHON_HOME: "C:\\Python33-x64" + PYTHON_VERSION: "3.3" + PYTHON_ARCH: "64" + - TOXENV: "3.4-40" + TOXPYTHON: "C:\\Python34\\python.exe" + WINDOWS_SDK_VERSION: "v7.1" + PYTHON_HOME: "C:\\Python34" + PYTHON_VERSION: "3.4" + PYTHON_ARCH: "32" + - TOXENV: "3.4-40" + TOXPYTHON: "C:\\Python34-x64\\python.exe" + WINDOWS_SDK_VERSION: "v7.1" + PYTHON_HOME: "C:\\Python34-x64" + PYTHON_VERSION: "3.4" + PYTHON_ARCH: "64" +init: + - "ECHO %TOXENV%" + - ps: "ls C:\\Python*" +install: + - "powershell ci\\appveyor-bootstrap.ps1" +test_script: + - "%PYTHON_HOME%\\Scripts\\tox --version" + - "%PYTHON_HOME%\\Scripts\\virtualenv --version" + - "%PYTHON_HOME%\\Scripts\\pip --version" + - "%WITH_COMPILER% %PYTHON_HOME%\\Scripts\\tox" +artifacts: + - path: dist\* diff --git a/ci/appveyor-bootstrap.ps1 b/ci/appveyor-bootstrap.ps1 new file mode 100644 index 00000000..1dd53420 --- /dev/null +++ b/ci/appveyor-bootstrap.ps1 @@ -0,0 +1,88 @@ +# Source: https://github.com/pypa/python-packaging-user-guide/blob/master/source/code/install.ps1 +# Sample script to install Python and pip under Windows +# Authors: Olivier Grisel and Kyle Kastner +# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/ + +$BASE_URL = "https://www.python.org/ftp/python/" +$GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py" +$GET_PIP_PATH = "C:\get-pip.py" + + +function DownloadPython ($python_version, $platform_suffix) { + $webclient = New-Object System.Net.WebClient + $filename = "python-" + $python_version + $platform_suffix + ".msi" + $url = $BASE_URL + $python_version + "/" + $filename + + $basedir = $pwd.Path + "\" + $filepath = $basedir + $filename + if (Test-Path $filename) { + Write-Host "Reusing" $filepath + return $filepath + } + + # Download and retry up to 5 times in case of network transient errors. + Write-Host "Downloading" $filename "from" $url + $retry_attempts = 3 + for($i=0; $i -lt $retry_attempts; $i++){ + try { + $webclient.DownloadFile($url, $filepath) + break + } + Catch [Exception]{ + Start-Sleep 1 + } + } + Write-Host "File saved at" $filepath + return $filepath +} + + +function InstallPython ($python_version, $architecture, $python_home) { + Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home + if (Test-Path $python_home) { + Write-Host $python_home "already exists, skipping." + return $false + } + if ($architecture -eq "32") { + $platform_suffix = "" + } else { + $platform_suffix = ".amd64" + } + $filepath = DownloadPython $python_version $platform_suffix + Write-Host "Installing" $filepath "to" $python_home + $args = "/qn /i $filepath TARGETDIR=$python_home" + Write-Host "msiexec.exe" $args + Start-Process -FilePath "msiexec.exe" -ArgumentList $args -Wait -Passthru + Write-Host "Python $python_version ($architecture) installation complete" + return $true +} + + +function InstallPip ($python_home) { + $pip_path = $python_home + "/Scripts/pip.exe" + $python_path = $python_home + "/python.exe" + if (-not(Test-Path $pip_path)) { + Write-Host "Installing pip..." + $webclient = New-Object System.Net.WebClient + $webclient.DownloadFile($GET_PIP_URL, $GET_PIP_PATH) + Write-Host "Executing:" $python_path $GET_PIP_PATH + Start-Process -FilePath "$python_path" -ArgumentList "$GET_PIP_PATH" -Wait -Passthru + } else { + Write-Host "pip already installed." + } +} + +function InstallPackage ($python_home, $pkg) { + $pip_path = $python_home + "/Scripts/pip.exe" + & $pip_path install $pkg +} + +function main () { + InstallPython $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON_HOME + InstallPip $env:PYTHON_HOME + InstallPackage $env:PYTHON_HOME setuptools + InstallPackage $env:PYTHON_HOME wheel + InstallPackage $env:PYTHON_HOME tox +} + +main diff --git a/ci/appveyor-with-compiler.cmd b/ci/appveyor-with-compiler.cmd new file mode 100644 index 00000000..3619733b --- /dev/null +++ b/ci/appveyor-with-compiler.cmd @@ -0,0 +1,37 @@ +:: To build extensions for 64 bit Python 3, we need to configure environment +:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of: +:: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1) +:: +:: To build extensions for 64 bit Python 2, we need to configure environment +:: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of: +:: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0) +:: +:: 32 bit builds do not require specific environment configurations. +:: +:: Note: this script needs to be run with the /E:ON and /V:ON flags for the +:: cmd interpreter, at least for (SDK v7.0) +:: +:: More details at: +:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows +:: http://stackoverflow.com/a/13751649/163740 +:: +:: Author: Olivier Grisel +:: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/ +@ECHO OFF + +SET COMMAND_TO_RUN=%* +SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows + +IF "%PYTHON_ARCH%"=="64" ( + ECHO SDK: %WINDOWS_SDK_VERSION% ARCH: %PYTHON_ARCH% + SET DISTUTILS_USE_SDK=1 + SET MSSdk=1 + "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION% + "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release + ECHO Executing: %COMMAND_TO_RUN% + call %COMMAND_TO_RUN% || EXIT 1 +) ELSE ( + ECHO SDK: %WINDOWS_SDK_VERSION% ARCH: %PYTHON_ARCH% + ECHO Executing: %COMMAND_TO_RUN% + call %COMMAND_TO_RUN% || EXIT 1 +) diff --git a/cov-core/.gitignore b/cov-core/.gitignore deleted file mode 100644 index 46a6d937..00000000 --- a/cov-core/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -*.pyo -*.pyc -*egg-info -build -dist -env* diff --git a/cov-core/MANIFEST.in b/cov-core/MANIFEST.in deleted file mode 100644 index 9ad66a9b..00000000 --- a/cov-core/MANIFEST.in +++ /dev/null @@ -1,5 +0,0 @@ -include README.rst -include LICENSE.txt -include setup.py -include cov_core.py -include cov_core_init.py diff --git a/cov-core/README.rst b/cov-core/README.rst deleted file mode 100644 index 1a41daf2..00000000 --- a/cov-core/README.rst +++ /dev/null @@ -1,5 +0,0 @@ -cov-core -======== - -This is a lib package for use by pytest-cov, nose-cov and nose2-cov. Unless you're developing a -coverage plugin for a test framework, you probably want one of those. diff --git a/cov-core/cov_core_init.py b/cov-core/cov_core_init.py deleted file mode 100644 index f91ad34c..00000000 --- a/cov-core/cov_core_init.py +++ /dev/null @@ -1,57 +0,0 @@ -"""Activate coverage at python startup if appropriate. - -The python site initialisation will ensure that anything we import -will be removed and not visible at the end of python startup. However -we minimise all work by putting these init actions in this separate -module and only importing what is needed when needed. - -For normal python startup when coverage should not be activated the pth -file checks a single env var and does not import or call the init fn -here. - -For python startup when an ancestor process has set the env indicating -that code coverage is being collected we activate coverage based on -info passed via env vars. -""" - - -UNIQUE_SEP = '084031f3d2994d40a88c8b699b69e148' - -import cov_core # noqa: register multiprocessing handler - - -def init(): - - # Any errors encountered should only prevent coverage from - # starting, it should not cause python to complain that importing - # of site failed. - try: - - # Only continue if ancestor process has set everything needed in - # the env. - import os - - cov_source = os.environ.get('COV_CORE_SOURCE') - cov_config = os.environ.get('COV_CORE_CONFIG') - if cov_config: - - # Import what we need to activate coverage. - import coverage - - # Determine all source roots. - if not cov_source: - cov_source = None - else: - cov_source = cov_source.split(UNIQUE_SEP) - - # Activate coverage for this process. - cov = coverage.coverage(source=cov_source, - data_suffix=True, - config_file=cov_config, - auto_data=True) - cov.erase() - cov.start() - return cov - - except Exception: - pass diff --git a/cov-core/setup.py b/cov-core/setup.py deleted file mode 100644 index bd6853f0..00000000 --- a/cov-core/setup.py +++ /dev/null @@ -1,77 +0,0 @@ -import setuptools -import sys -import os - -# The name of the path file must appear after easy-install.pth so that -# cov_core has been added to the sys.path and cov_core_init can be -# imported. -PTH_FILE_NAME = 'init_cov_core.pth' - -# The line in the path file must begin with "import" -# so that site.py will exec it. -PTH_FILE = '''\ -import os; exec(%r) -''' % ''' -if 'COV_CORE_SOURCE' in os.environ: - try: - import cov_core_init - cov_core_init.init() - except ImportError: - pass -''' - -PTH_FILE_FAILURE = ''' -Subprocesses WILL NOT have coverage collected. - -To measure subprocesses put the following in a pth file called %s: -%s -''' % (PTH_FILE_NAME, PTH_FILE) - -setuptools.setup(name='cov-core', - version='1.15.0', - description='plugin core for use by pytest-cov, ' - 'nose-cov and nose2-cov', - long_description=open('README.rst').read().strip(), - author='Marc Schlaich', - author_email='marc.schlaich@gmail.com', - url='https://github.com/schlamar/cov-core', - py_modules=['cov_core', - 'cov_core_init'], - install_requires=['coverage>=3.6'], - license='MIT License', - zip_safe=False, - keywords='cover coverage', - classifiers=['Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.4', - 'Programming Language :: Python :: 2.5', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.0', - 'Programming Language :: Python :: 3.1', - 'Topic :: Software Development :: Testing']) - -if sys.argv[1] in ('install', 'develop'): - for path in sys.path: - if (path.endswith('site-packages')) or (path.endswith('dist-packages') - and 'local' in path): - path = os.path.join(path, PTH_FILE_NAME) - try: - pth_file = open(path, 'w') - pth_file.write(PTH_FILE) - pth_file.close() - sys.stdout.write('\nWrote pth file for subprocess ' - 'measurement to %s\n' % path) - break - except Exception: - sys.stdout.write('\nFailed to write pth file for subprocess ' - 'measurement to %s\n' % path) - sys.stdout.write(PTH_FILE_FAILURE) - break - else: - sys.stdout.write('\nFailed to find site-packages or dist-packages ' - 'dir to put pth file in.\n') - sys.stdout.write(PTH_FILE_FAILURE) diff --git a/docs/authors.rst b/docs/authors.rst new file mode 100644 index 00000000..e122f914 --- /dev/null +++ b/docs/authors.rst @@ -0,0 +1 @@ +.. include:: ../AUTHORS.rst diff --git a/docs/changelog.rst b/docs/changelog.rst new file mode 100644 index 00000000..565b0521 --- /dev/null +++ b/docs/changelog.rst @@ -0,0 +1 @@ +.. include:: ../CHANGELOG.rst diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000..d48985a3 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +import os + + +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.autosummary', + 'sphinx.ext.todo', + 'sphinx.ext.coverage', + 'sphinx.ext.ifconfig', + 'sphinx.ext.viewcode', + 'sphinxcontrib.napoleon' +] +if os.getenv('SPELLCHECK'): + extensions += 'sphinxcontrib.spelling', + spelling_show_suggestions = True + spelling_lang = 'en_US' + +source_suffix = '.rst' +master_doc = 'index' +project = 'pytest-cov' +year = '2015' +author = 'Ionel Cristian Mărieș' +copyright = '{0}, {1}'.format(year, author) +version = release = '2.0.0' +import sphinx_py3doc_enhanced_theme +html_theme = "sphinx_py3doc_enhanced_theme" +html_theme_path = [sphinx_py3doc_enhanced_theme.get_html_theme_path()] +html_theme_options = { + 'githuburl': 'https://github.com/schlamar/pytest-cov/' +} + +pygments_style = 'trac' +templates_path = ['.'] +html_use_smartypants = True +html_last_updated_fmt = '%b %d, %Y' +html_split_index = True +html_sidebars = { + '**': ['searchbox.html', 'globaltoc.html', 'sourcelink.html'], +} +html_short_title = '%s-%s' % (project, version) diff --git a/docs/contributing.rst b/docs/contributing.rst new file mode 100644 index 00000000..e582053e --- /dev/null +++ b/docs/contributing.rst @@ -0,0 +1 @@ +.. include:: ../CONTRIBUTING.rst diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..1d1c58c1 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,23 @@ +Welcome to pytest-cov's documentation! +====================================== + +Contents: + +.. toctree:: + :maxdepth: 2 + + readme + installation + usage + reference/index + contributing + authors + changelog + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/docs/installation.rst b/docs/installation.rst new file mode 100644 index 00000000..d12d3475 --- /dev/null +++ b/docs/installation.rst @@ -0,0 +1,7 @@ +============ +Installation +============ + +At the command line:: + + pip install pytest-cov diff --git a/docs/readme.rst b/docs/readme.rst new file mode 100644 index 00000000..6be290b8 --- /dev/null +++ b/docs/readme.rst @@ -0,0 +1,5 @@ +######## +Overview +######## + +.. include:: ../README.rst diff --git a/docs/reference/index.rst b/docs/reference/index.rst new file mode 100644 index 00000000..5fd2c7f9 --- /dev/null +++ b/docs/reference/index.rst @@ -0,0 +1,7 @@ +Reference +========= + +.. toctree:: + :glob: + + pytest_cov* diff --git a/docs/reference/pytest_cover.rst b/docs/reference/pytest_cover.rst new file mode 100644 index 00000000..caf88b39 --- /dev/null +++ b/docs/reference/pytest_cover.rst @@ -0,0 +1,5 @@ +pytest_cov +============================= + +.. automodule:: pytest_cov + :members: diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 00000000..1632a968 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,4 @@ +sphinx +sphinxcontrib-napoleon +sphinx-py3doc-enhanced-theme +-e . diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt new file mode 100644 index 00000000..f95eb78d --- /dev/null +++ b/docs/spelling_wordlist.txt @@ -0,0 +1,11 @@ +builtin +builtins +classmethod +staticmethod +classmethods +staticmethods +args +kwargs +callstack +Changelog +Indices diff --git a/docs/usage.rst b/docs/usage.rst new file mode 100644 index 00000000..89b4912e --- /dev/null +++ b/docs/usage.rst @@ -0,0 +1,7 @@ +===== +Usage +===== + +To use pytest-cov in a project:: + + import pytest_cov diff --git a/example-tox-project/.coveragerc b/example/.coveragerc similarity index 100% rename from example-tox-project/.coveragerc rename to example/.coveragerc diff --git a/example-tox-project/mylib/__init__.py b/example/mylib/__init__.py similarity index 100% rename from example-tox-project/mylib/__init__.py rename to example/mylib/__init__.py diff --git a/example-tox-project/setup.py b/example/setup.py similarity index 100% rename from example-tox-project/setup.py rename to example/setup.py diff --git a/example-tox-project/tests/test_mylib.py b/example/tests/test_mylib.py similarity index 100% rename from example-tox-project/tests/test_mylib.py rename to example/tests/test_mylib.py diff --git a/example-tox-project/tox.ini b/example/tox.ini similarity index 100% rename from example-tox-project/tox.ini rename to example/tox.ini diff --git a/pytest-cov/.gitignore b/pytest-cov/.gitignore deleted file mode 100644 index cbb44d89..00000000 --- a/pytest-cov/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -*.pyo -*.pyc -*egg-info -build -dist -env* -.tox -.coverage* diff --git a/pytest-cov/LICENSE.txt b/pytest-cov/LICENSE.txt deleted file mode 100644 index 5b3634b4..00000000 --- a/pytest-cov/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License - -Copyright (c) 2010 Meme Dough - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/pytest-cov/MANIFEST.in b/pytest-cov/MANIFEST.in deleted file mode 100644 index 99e6799f..00000000 --- a/pytest-cov/MANIFEST.in +++ /dev/null @@ -1,5 +0,0 @@ -include README.rst -include LICENSE.txt -include setup.py -include pytest_cov.py -include test_pytest_cov.py diff --git a/pytest-cov/README.rst b/pytest-cov/README.rst deleted file mode 100644 index 9100bb8f..00000000 --- a/pytest-cov/README.rst +++ /dev/null @@ -1,272 +0,0 @@ -pytest-cov -========== - -.. image:: https://travis-ci.org/schlamar/pytest-cov.svg?branch=master - :target: https://travis-ci.org/schlamar/pytest-cov - :alt: Build status - -.. image:: https://pypip.in/download/pytest-cov/badge.png - :target: https://pypi.python.org/pypi//pytest-cov/ - :alt: Downloads - -.. image:: https://pypip.in/version/pytest-cov/badge.png - :target: https://pypi.python.org/pypi/pytest-cov/ - :alt: Latest Version - -.. image:: https://pypip.in/license/pytest-cov/badge.png - :target: https://pypi.python.org/pypi/pytest-cov/ - :alt: License - -This plugin produces coverage reports. It supports centralised testing and distributed testing in -both load and each modes. It also supports coverage of subprocesses. - -All features offered by the coverage package should be available, either through pytest-cov or -through coverage's config file. - - -Installation ------------- - -Install with pip:: - - pip install pytest-cov - -For distributed testing support install pytest-xdist:: - - pip install pytest-xdist - -.. NOTE:: - - Ensure you use pip instead of easy_install as the latter does not correctly install the - init_cov_core.pth file needed for subprocess measurement. - - -Uninstallation --------------- - -Uninstall with pip:: - - pip uninstall pytest-cov - pip uninstall cov-core - -.. NOTE:: - - Ensure that you manually delete the init_cov_core.pth file in your site-packages directory. - - This file starts coverage collection of subprocesses if appropriate during site initialisation - at python startup. - - -Usage ------ - -Centralised Testing -~~~~~~~~~~~~~~~~~~~ - -Centralised testing will report on the combined coverage of the main process and all of it's -subprocesses. - -Running centralised testing:: - - py.test --cov-source myproj tests/ - -Shows a terminal report:: - - -------------------- coverage: platform linux2, python 2.6.4-final-0 --------------------- - Name Stmts Miss Cover - ---------------------------------------- - myproj/__init__ 2 0 100% - myproj/myproj 257 13 94% - myproj/feature4286 94 7 92% - ---------------------------------------- - TOTAL 353 20 94% - - -Distributed Testing: Load -~~~~~~~~~~~~~~~~~~~~~~~~~ - -Distributed testing with dist mode set to load will report on the combined coverage of all slaves. -The slaves may be spread out over any number of hosts and each slave may be located anywhere on the -file system. Each slave will have it's subprocesses measured. - -Running distributed testing with dist mode set to load:: - - py.test --cov-source myproj -n 2 tests/ - -Shows a terminal report:: - - -------------------- coverage: platform linux2, python 2.6.4-final-0 --------------------- - Name Stmts Miss Cover - ---------------------------------------- - myproj/__init__ 2 0 100% - myproj/myproj 257 13 94% - myproj/feature4286 94 7 92% - ---------------------------------------- - TOTAL 353 20 94% - - -Again but spread over different hosts and different directories:: - - py.test --cov-source myproj --dist load - --tx ssh=memedough@host1//chdir=testenv1 - --tx ssh=memedough@host2//chdir=/tmp/testenv2//python=/tmp/env1/bin/python - --rsyncdir myproj --rsyncdir tests --rsync examples - tests/ - -Shows a terminal report:: - - -------------------- coverage: platform linux2, python 2.6.4-final-0 --------------------- - Name Stmts Miss Cover - ---------------------------------------- - myproj/__init__ 2 0 100% - myproj/myproj 257 13 94% - myproj/feature4286 94 7 92% - ---------------------------------------- - TOTAL 353 20 94% - - -Distributed Testing: Each -~~~~~~~~~~~~~~~~~~~~~~~~~ - -Distributed testing with dist mode set to each will report on the combined coverage of all slaves. -Since each slave is running all tests this allows generating a combined coverage report for multiple -environments. - -Running distributed testing with dist mode set to each:: - - py.test --cov-source myproj --dist each - --tx popen//chdir=/tmp/testenv3//python=/usr/local/python27/bin/python - --tx ssh=memedough@host2//chdir=/tmp/testenv4//python=/tmp/env2/bin/python - --rsyncdir myproj --rsyncdir tests --rsync examples - tests/ - -Shows a terminal report:: - - ---------------------------------------- coverage ---------------------------------------- - platform linux2, python 2.6.5-final-0 - platform linux2, python 2.7.0-final-0 - Name Stmts Miss Cover - ---------------------------------------- - myproj/__init__ 2 0 100% - myproj/myproj 257 13 94% - myproj/feature4286 94 7 92% - ---------------------------------------- - TOTAL 353 20 94% - - -Reporting ---------- - -It is possible to generate any combination of the reports for a single test run. - -The available reports are terminal (with or without missing line numbers shown), HTML, XML and -annotated source code. - -The terminal report without line numbers (default):: - - py.test --cov-report term --cov-source myproj tests/ - - -------------------- coverage: platform linux2, python 2.6.4-final-0 --------------------- - Name Stmts Miss Cover - ---------------------------------------- - myproj/__init__ 2 0 100% - myproj/myproj 257 13 94% - myproj/feature4286 94 7 92% - ---------------------------------------- - TOTAL 353 20 94% - - -The terminal report with line numbers:: - - py.test --cov-report term-missing --cov-source myproj tests/ - - -------------------- coverage: platform linux2, python 2.6.4-final-0 --------------------- - Name Stmts Miss Cover Missing - -------------------------------------------------- - myproj/__init__ 2 0 100% - myproj/myproj 257 13 94% 24-26, 99, 149, 233-236, 297-298, 369-370 - myproj/feature4286 94 7 92% 183-188, 197 - -------------------------------------------------- - TOTAL 353 20 94% - - -These three report options output to files without showing anything on the terminal:: - - py.test --cov-report html - --cov-report xml - --cov-report annotate - --cov-source myproj tests/ - -The final report option can also suppress printing to the terminal:: - - py.test --cov-report= --cov-source myproj tests/ - -This mode can be especially useful on continuous integration servers, where a coverage file -is needed for subsequent processing, but no local report needs to be viewed. For example, -tests run on Travis-CI could produce a .coverage file for use with Coveralls. - -Coverage Data File ------------------- - -The data file is erased at the beginning of testing to ensure clean data for each test run. - -The data file is left at the end of testing so that it is possible to use normal coverage tools to -examine it. - - -Coverage Config File --------------------- - -This plugin provides a clean minimal set of command line options that are added to pytest. For -further control of coverage use a coverage config file. - -For example if tests are contained within the directory tree being measured the tests may be -excluded if desired by using a .coveragerc file with the omit option set:: - - py.test --cov-config .coveragerc - --cov-source myproj - myproj/tests/ - -Where the .coveragerc file contains file globs:: - - [run] - omit = tests/* - -For full details refer to the `coverage config file`_ documentation. - -.. _`coverage config file`: http://nedbatchelder.com/code/coverage/config.html - -Note that this plugin controls some options and setting the option in the config file will have no -effect. These include specifying source to be measured (source option) and all data file handling -(data_file and parallel options). - - -Limitations ------------ - -For distributed testing the slaves must have the pytest-cov package installed. This is needed since -the plugin must be registered through setuptools / distribute for pytest to start the plugin on the -slave. - -For subprocess measurement environment variables must make it from the main process to the -subprocess. The python used by the subprocess must have pytest-cov installed. The subprocess must -do normal site initialisation so that the environment variables can be detected and coverage -started. - - -Acknowledgements ----------------- - -Whilst this plugin has been built fresh from the ground up it has been influenced by the work done -on pytest-coverage (Ross Lawley, James Mills, Holger Krekel) and nose-cover (Jason Pellerin) which are -other coverage plugins. - -Ned Batchelder for coverage and its ability to combine the coverage results of parallel runs. - -Holger Krekel for pytest with its distributed testing support. - -Jason Pellerin for nose. - -Michael Foord for unittest2. - -No doubt others have contributed to these tools as well. diff --git a/pytest-cov/setup.py b/pytest-cov/setup.py deleted file mode 100644 index ec7623a5..00000000 --- a/pytest-cov/setup.py +++ /dev/null @@ -1,32 +0,0 @@ -import setuptools - -setuptools.setup(name='pytest-cov', - version='1.8.1', - description='py.test plugin for coverage reporting with ' - 'support for both centralised and distributed testing, ' - 'including subprocesses and multiprocessing', - long_description=open('README.rst').read().strip(), - author='Marc Schlaich', - author_email='marc.schlaich@gmail.com', - url='https://github.com/schlamar/pytest-cov', - py_modules=['pytest_cov'], - install_requires=['py>=1.4.22', - 'pytest>=2.6.0', - 'coverage>=3.7.1', - 'cov-core>=1.14.0'], - entry_points={'pytest11': ['pytest_cov = pytest_cov']}, - license='MIT License', - zip_safe=False, - keywords='py.test pytest cover coverage distributed parallel', - classifiers=['Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.4', - 'Programming Language :: Python :: 2.5', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.0', - 'Programming Language :: Python :: 3.1', - 'Topic :: Software Development :: Testing']) diff --git a/pytest-cov/tox.ini b/pytest-cov/tox.ini deleted file mode 100644 index 830ea8d0..00000000 --- a/pytest-cov/tox.ini +++ /dev/null @@ -1,14 +0,0 @@ -[tox] -envlist = py26, py27, pypy, pypy3, py32, py33, py34 - -[testenv] -usedevelop = True -setenv = - PYTHONHASHSEED = random -deps = - {env:COV_CORE_DEP:../cov-core} - execnet>=1.2.0,<1.3.0 - pytest>=2.6.4,<2.7.0 - pytest-xdist - virtualenv -commands = py.test -v test_pytest_cov.py {posargs} diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..9846450e --- /dev/null +++ b/setup.cfg @@ -0,0 +1,52 @@ +[bumpversion] +current_version = 2.0.0 +commit = True +tag = True + +[bdist_wheel] +universal = 1 + +[aliases] +release = register clean --all sdist bdist_wheel + +[flake8] +max-line-length = 140 +exclude = tests/*,*/migrations/*,*/south_migrations/* + +[bumpversion:file:setup.py] + +[bumpversion:file:docs/conf.py] + +[bumpversion:file:src/pytest_cov/__init__.py] + +[pytest] +norecursedirs = + .git + .tox + .env + dist + build + south_migrations + migrations + example +python_files = + test_*.py + *_test.py + tests.py +addopts = + -rxEfs + --strict + --ignore=docs/conf.py + --ignore=setup.py + --ignore=src + --ignore=ci + --doctest-modules + --doctest-glob=\*.rst + --tb=short + +[isort] +force_single_line = True +line_length = 120 +known_first_party = pytest_cov +default_section = THIRDPARTY +forced_separate = test_pytest_cover diff --git a/setup.py b/setup.py index 60684932..adb70197 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,139 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +from __future__ import absolute_import, print_function + +import io +from itertools import chain +import re +from glob import glob +from os.path import basename +from os.path import dirname +from os.path import join +from os.path import splitext +from distutils.command.build import build + +from setuptools import Command +from setuptools import find_packages from setuptools import setup +from setuptools.command.develop import develop +from setuptools.command.install_lib import install_lib +from setuptools.command.easy_install import easy_install + + +def read(*names, **kwargs): + return io.open( + join(dirname(__file__), *names), + encoding=kwargs.get('encoding', 'utf8') + ).read() + + +class BuildWithPTH(build): + def run(self): + build.run(self) + path = join(dirname(__file__), 'src', 'pytest-cov.pth') + dest = join(self.build_lib, basename(path)) + self.copy_file(path, dest) + + +class EasyInstallWithPTH(easy_install): + def run(self): + easy_install.run(self) + path = join(dirname(__file__), 'src', 'pytest-cov.pth') + dest = join(self.install_dir, basename(path)) + self.copy_file(path, dest) + + +class InstallLibWithPTH(install_lib): + def run(self): + install_lib.run(self) + path = join(dirname(__file__), 'src', 'pytest-cov.pth') + dest = join(self.install_dir, basename(path)) + self.copy_file(path, dest) + self.outputs = [dest] + + def get_outputs(self): + return chain(install_lib.get_outputs(self), self.outputs) + + +class DevelopWithPTH(develop): + def run(self): + develop.run(self) + path = join(dirname(__file__), 'src', 'pytest-cov.pth') + dest = join(self.install_dir, basename(path)) + self.copy_file(path, dest) + + +class GeneratePTH(Command): + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + with open(join(dirname(__file__), 'src', 'pytest-cov.pth'), 'w') as fh: + with open(join(dirname(__file__), 'src', 'pytest-cov.embed')) as sh: + fh.write( + 'import os, sys;' + 'exec(%r)' % sh.read().replace(' ', ' ') + ) -setup() +setup( + name='pytest-cov', + version='2.0.0', + license='MIT', + description='Pytest plugin for measuring coverage.', + long_description='%s\n%s' % (read('README.rst'), re.sub(':[a-z]+:`~?(.*?)`', r'``\1``', read('CHANGELOG.rst'))), + author='Marc Schlaich', + author_email='marc.schlaich@gmail.com', + url='https://github.com/schlamar/pytest-cov', + packages=find_packages('src'), + package_dir={'': 'src'}, + py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')], + include_package_data=True, + zip_safe=False, + classifiers=[ + # complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: Unix', + 'Operating System :: POSIX', + 'Operating System :: Microsoft :: Windows', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', + 'Topic :: Utilities', + 'Topic :: Software Development :: Testing' + ], + keywords=[ + 'cover', 'coverage', 'pytest', 'py.test', 'distributed', 'parallel', + ], + install_requires=[ + 'pytest>=2.6.0', + 'coverage>=3.7.1' + ], + extras_require={ + }, + entry_points={ + 'pytest11': [ + 'pytest_cov = pytest_cov.plugin', + ], + 'console_scripts': [ + ] + }, + cmdclass={ + 'build': BuildWithPTH, + 'easy_install': EasyInstallWithPTH, + 'install_lib': InstallLibWithPTH, + 'develop': DevelopWithPTH, + 'genpth': GeneratePTH, + }, +) diff --git a/src/pytest-cov.embed b/src/pytest-cov.embed new file mode 100644 index 00000000..31f2fdab --- /dev/null +++ b/src/pytest-cov.embed @@ -0,0 +1,10 @@ +if 'COV_CORE_SOURCE' in os.environ: + try: + from pytest_cov.embed import init + init() + except ImportError: + sys.stderr.write( + "Failed to setup coverage." + "Sources: {[COV_CORE_SOURCE]!r}" + "Config: {[COV_CORE_CONFIG]!r}" + "Exception: {!r}\n".format(os.environ, exc)) diff --git a/src/pytest-cov.pth b/src/pytest-cov.pth new file mode 100644 index 00000000..8734b5ef --- /dev/null +++ b/src/pytest-cov.pth @@ -0,0 +1 @@ +import os, sys;exec('if \'COV_CORE_SOURCE\' in os.environ:\n try:\n from pytest_cov.embed import init\n init()\n except ImportError:\n sys.stderr.write(\n "Failed to setup coverage."\n "Sources: {[COV_CORE_SOURCE]!r}"\n "Config: {[COV_CORE_CONFIG]!r}"\n "Exception: {!r}\\n".format(os.environ, exc))\n') diff --git a/src/pytest_cov/__init__.py b/src/pytest_cov/__init__.py new file mode 100644 index 00000000..8c0d5d5b --- /dev/null +++ b/src/pytest_cov/__init__.py @@ -0,0 +1 @@ +__version__ = "2.0.0" diff --git a/src/pytest_cov/embed.py b/src/pytest_cov/embed.py new file mode 100644 index 00000000..3cfc4c74 --- /dev/null +++ b/src/pytest_cov/embed.py @@ -0,0 +1,61 @@ +"""Activate coverage at python startup if appropriate. + +The python site initialisation will ensure that anything we import +will be removed and not visible at the end of python startup. However +we minimise all work by putting these init actions in this separate +module and only importing what is needed when needed. + +For normal python startup when coverage should not be activated the pth +file checks a single env var and does not import or call the init fn +here. + +For python startup when an ancestor process has set the env indicating +that code coverage is being collected we activate coverage based on +info passed via env vars. +""" +import os + + +def multiprocessing_start(obj): + cov = init() + if cov: + multiprocessing.util.Finalize(None, multiprocessing_finish, args=(cov,), exitpriority=1000) + + +def multiprocessing_finish(cov): + cov.stop() + cov.save() + + +try: + import multiprocessing.util +except ImportError: + pass +else: + multiprocessing.util.register_after_fork(multiprocessing_start, multiprocessing_start) + + +def init(): + # Only continue if ancestor process has set everything needed in + # the env. + + cov_source = os.environ.get('COV_CORE_SOURCE') + cov_config = os.environ.get('COV_CORE_CONFIG') + if cov_config: + # Import what we need to activate coverage. + import coverage + + # Determine all source roots. + if not cov_source: + cov_source = None + else: + cov_source = cov_source.split(os.pathsep) + + # Activate coverage for this process. + cov = coverage.coverage(source=cov_source, + data_suffix=True, + config_file=cov_config, + auto_data=True) + cov.erase() + cov.start() + return cov diff --git a/cov-core/cov_core.py b/src/pytest_cov/engine.py similarity index 92% rename from cov-core/cov_core.py rename to src/pytest_cov/engine.py index b948178a..4c867cd9 100644 --- a/cov-core/cov_core.py +++ b/src/pytest_cov/engine.py @@ -1,32 +1,9 @@ """Coverage controllers for use by pytest-cov and nose-cov.""" - -from cov_core_init import UNIQUE_SEP -import cov_core_init -import coverage +import os import socket import sys -import os - - -def multiprocessing_start(obj): - cov = cov_core_init.init() - if cov: - import multiprocessing.util - multiprocessing.util.Finalize( - None, multiprocessing_finish, args=(cov,), exitpriority=1000) - -def multiprocessing_finish(cov): - cov.stop() - cov.save() - - -try: - import multiprocessing.util - multiprocessing.util.register_after_fork(multiprocessing_start, - multiprocessing_start) -except ImportError: - pass +import coverage class CovController(object): @@ -47,11 +24,10 @@ def __init__(self, cov_source, cov_report, cov_config, config=None, nodeid=None) def set_env(self): """Put info about coverage into the env so that subprocesses can activate coverage.""" - if self.cov_source is None: os.environ['COV_CORE_SOURCE'] = '' else: - os.environ['COV_CORE_SOURCE'] = UNIQUE_SEP.join(self.cov_source) + os.environ['COV_CORE_SOURCE'] = os.pathsep.join(self.cov_source) os.environ['COV_CORE_CONFIG'] = self.cov_config @staticmethod @@ -96,7 +72,7 @@ def summary(self, stream): # Produce terminal report if wanted. if 'term' in self.cov_report or 'term-missing' in self.cov_report: - show_missing = 'term-missing' in self.cov_report + show_missing = ('term-missing' in self.cov_report) or None total = self.cov.report(show_missing=show_missing, ignore_errors=True, file=stream) # Produce annotated source code report if wanted. diff --git a/pytest-cov/pytest_cov.py b/src/pytest_cov/plugin.py similarity index 82% rename from pytest-cov/pytest_cov.py rename to src/pytest_cov/plugin.py index 0ac9dd81..7abb0bef 100644 --- a/pytest-cov/pytest_cov.py +++ b/src/pytest_cov/plugin.py @@ -1,15 +1,14 @@ """Coverage plugin for pytest.""" - import os import pytest -import cov_core -import cov_core_init +from . import embed +from . import engine class CoverageError(Exception): - '''Indicates that our coverage is too low''' + """Indicates that our coverage is too low""" def pytest_addoption(parser): @@ -17,12 +16,8 @@ def pytest_addoption(parser): group = parser.getgroup( 'cov', 'coverage reporting with distributed testing support') - - group.addoption('--cov', action='append', nargs='?', dest='cov', - const=True, default=[], - help='Enable coverage plugin.') - group.addoption('--cov-source', action='append', default=[], - metavar='path', dest='cov_source', + group.addoption('--cov', action='append', default=[], metavar='path', + nargs='?', const=True, dest='cov_source', help='measure coverage for filesystem path ' '(multi-allowed)') group.addoption('--cov-report', action='append', default=[], @@ -38,20 +33,16 @@ def pytest_addoption(parser): dest='no_cov_on_fail', help='do not report coverage if test run fails, ' 'default: False') - group.addoption('--cov-min', action='store', metavar='MIN', type='int', + group.addoption('--cov-fail-under', action='store', metavar='MIN', type='int', help='Fail if the total coverage is less than MIN.') @pytest.mark.tryfirst def pytest_load_initial_conftests(early_config, parser, args): ns = parser.parse_known_args(args) - if ns.cov and ns.cov != [True]: - print ('Deprecation warning: --cov shouldn\'t be used ' - 'with additional source arguments anymore. Use ' - '--cov-source instead.') - ns.cov_source.extend(ns.cov) + ns.cov = bool(ns.cov_source) - if not ns.cov_source: + if ns.cov_source == [True]: ns.cov_source = None if not ns.cov_report: @@ -66,7 +57,7 @@ def pytest_load_initial_conftests(early_config, parser, args): def pytest_configure(config): """Activate coverage plugin if appropriate.""" - if config.getvalue('cov'): + if config.getvalue('cov_source'): if not config.pluginmanager.hasplugin('_cov'): plugin = CovPlugin(config.option, config.pluginmanager, start=False) @@ -100,15 +91,15 @@ def __init__(self, options, pluginmanager, start=True): getattr(options, 'distload', False) or getattr(options, 'dist', 'no') != 'no') if is_dist and start: - self.start(cov_core.DistMaster) + self.start(engine.DistMaster) elif start: - self.start(cov_core.Central) + self.start(engine.Central) # slave is started in pytest hook def start(self, controller_cls, config=None, nodeid=None): if config is None: - # fake config option for cov_core + # fake config option for engine class Config(object): option = self.options @@ -122,6 +113,9 @@ class Config(object): nodeid ) self.cov_controller.start() + cov_config = self.cov_controller.cov.config + if self.options.cov_fail_under is None and hasattr(cov_config, 'fail_under'): + self.options.cov_fail_under = cov_config.fail_under def pytest_sessionstart(self, session): """At session start determine our implementation and delegate to it.""" @@ -130,7 +124,7 @@ def pytest_sessionstart(self, session): if is_slave: nodeid = session.config.slaveinput.get('slaveid', getattr(session, 'nodeid')) - self.start(cov_core.DistSlave, session.config, nodeid) + self.start(engine.DistSlave, session.config, nodeid) def pytest_configure_node(self, node): """Delegate to our implementation. @@ -161,21 +155,21 @@ def pytest_terminal_summary(self, terminalreporter): if not (self.failed and self.options.no_cov_on_fail): total = self.cov_controller.summary(terminalreporter.writer) assert total is not None, 'Test coverage should never be `None`' - cov_min = self.options.cov_min - if cov_min is not None and total < cov_min: + cov_fail_under = self.options.cov_fail_under + if cov_fail_under is not None and total < cov_fail_under: raise CoverageError(('Required test coverage of %d%% not ' 'reached. Total coverage: %.2f%%') - % (self.options.cov_min, total)) + % (self.options.cov_fail_under, total)) def pytest_runtest_setup(self, item): if os.getpid() != self.pid: # test is run in another process than session, run # coverage manually - self.cov = cov_core_init.init() + self.cov = embed.init() def pytest_runtest_teardown(self, item): if self.cov is not None: - cov_core.multiprocessing_finish(self.cov) + embed.multiprocessing_finish(self.cov) self.cov = None diff --git a/tests/helper.py b/tests/helper.py new file mode 100644 index 00000000..3e7da4bb --- /dev/null +++ b/tests/helper.py @@ -0,0 +1,3 @@ +def do_stuff(): + a = 1 + return a diff --git a/pytest-cov/test_pytest_cov.py b/tests/test_pytest_cover.py similarity index 77% rename from pytest-cov/test_pytest_cov.py rename to tests/test_pytest_cover.py index b2a3ee3d..8b82dd3f 100644 --- a/pytest-cov/test_pytest_cov.py +++ b/tests/test_pytest_cover.py @@ -1,18 +1,18 @@ - +from distutils.version import StrictVersion import os import sys +import subprocess +import coverage import virtualenv - import py import pytest -import pytest_cov - +import pytest_cov.plugin pytest_plugins = 'pytester', 'cov' SCRIPT = ''' -import sys +import sys, helper def pytest_generate_tests(metafunc): for i in range(10): @@ -20,7 +20,7 @@ def pytest_generate_tests(metafunc): def test_foo(): x = True - assert x + helper.do_stuff() # get some coverage in some other completely different location if sys.version_info[0] > 5: assert False ''' @@ -85,7 +85,6 @@ def test_run_target(): p.join() ''' - SCRIPT_FAIL = ''' def test_fail(): assert False @@ -101,15 +100,15 @@ def test_central(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_central * %s *' % SCRIPT_RESULT, + 'test_central* %s *' % SCRIPT_RESULT, '*10 passed*' - ]) + ]) assert result.ret == 0 @@ -117,9 +116,9 @@ def test_cov_min_100(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', - '--cov-min=100', + '--cov-fail-under=100', script) assert result.ret == 1 @@ -129,9 +128,9 @@ def test_cov_min_50(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', - '--cov-min=50', + '--cov-fail-under=50', script) assert result.ret == 0 @@ -141,9 +140,9 @@ def test_cov_min_no_report(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=', - '--cov-min=50', + '--cov-fail-under=50', script) assert result.ret == 0 @@ -159,9 +158,9 @@ def test_central_nonspecific(testdir): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_central_nonspecific * %s *' % SCRIPT_RESULT, + 'test_central_nonspecific* %s *' % SCRIPT_RESULT, '*10 passed*' - ]) + ]) # multi-module coverage report assert result.stdout.lines[-3].startswith('TOTAL ') @@ -169,6 +168,22 @@ def test_central_nonspecific(testdir): assert result.ret == 0 +@pytest.mark.skipif('StrictVersion(coverage.__version__) <= StrictVersion("3.8")') +def test_cov_min_from_coveragerc(testdir): + script = testdir.makepyfile(SCRIPT) + testdir.tmpdir.join('.coveragerc').write(""" +[report] +fail_under = 100 +""") + + result = testdir.runpytest('-v', + '--cov=%s' % script.dirpath(), + '--cov-report=term-missing', + script) + + assert result.ret == 1 + + def test_central_coveragerc(testdir): script = testdir.makepyfile(SCRIPT) testdir.tmpdir.join('.coveragerc').write(COVERAGERC_SOURCE) @@ -180,12 +195,40 @@ def test_central_coveragerc(testdir): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_central_coveragerc * %s *' % SCRIPT_RESULT, + 'test_central_coveragerc* %s *' % SCRIPT_RESULT, + '*10 passed*', + ]) + + # single-module coverage report + assert result.stdout.lines[-3].startswith('test_central_coveragerc') + + assert result.ret == 0 + + +def test_show_missing_coveragerc(testdir): + script = testdir.makepyfile(SCRIPT) + testdir.tmpdir.join('.coveragerc').write(""" +[run] +source = . + +[report] +show_missing = true +""") + + result = testdir.runpytest('-v', + '--cov', + '--cov-report=term', + script) + + result.stdout.fnmatch_lines([ + '*- coverage: platform *, python * -*', + 'Name * Stmts * Miss * Cover * Missing', + 'test_show_missing_coveragerc* %s * 11' % SCRIPT_RESULT, '*10 passed*', - ]) + ]) # single-module coverage report - assert result.stdout.lines[-3].startswith('test_central_coveragerc ') + assert result.stdout.lines[-3].startswith('test_show_missing_coveragerc') assert result.ret == 0 @@ -194,7 +237,7 @@ def test_no_cov_on_fail(testdir): script = testdir.makepyfile(SCRIPT_FAIL) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', '--no-cov-on-fail', script) @@ -207,7 +250,7 @@ def test_dist_collocated(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', '--dist=load', '--tx=2*popen', @@ -215,9 +258,9 @@ def test_dist_collocated(testdir): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_dist_collocated * %s *' % SCRIPT_RESULT, + 'test_dist_collocated* %s *' % SCRIPT_RESULT, '*10 passed*' - ]) + ]) assert result.ret == 0 @@ -227,7 +270,7 @@ def test_dist_not_collocated(testdir): dir2 = testdir.mkdir('dir2') result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', '--dist=load', '--tx=popen//chdir=%s' % dir1, @@ -237,9 +280,9 @@ def test_dist_not_collocated(testdir): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_dist_not_collocated * %s *' % SCRIPT_RESULT, + 'test_dist_not_collocated* %s *' % SCRIPT_RESULT, '*10 passed*' - ]) + ]) assert result.ret == 0 @@ -249,15 +292,15 @@ def test_central_subprocess(testdir): parent_script = scripts.dirpath().join('parent_script.py') result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % scripts.dirpath(), + '--cov=%s' % scripts.dirpath(), '--cov-report=term-missing', parent_script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'child_script * %s *' % CHILD_SCRIPT_RESULT, - 'parent_script * %s *' % PARENT_SCRIPT_RESULT, - ]) + 'child_script* %s *' % CHILD_SCRIPT_RESULT, + 'parent_script* %s *' % PARENT_SCRIPT_RESULT, + ]) assert result.ret == 0 @@ -267,7 +310,7 @@ def test_dist_subprocess_collocated(testdir): parent_script = scripts.dirpath().join('parent_script.py') result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % scripts.dirpath(), + '--cov=%s' % scripts.dirpath(), '--cov-report=term-missing', '--dist=load', '--tx=2*popen', @@ -275,9 +318,9 @@ def test_dist_subprocess_collocated(testdir): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'child_script * %s *' % CHILD_SCRIPT_RESULT, - 'parent_script * %s *' % PARENT_SCRIPT_RESULT, - ]) + 'child_script* %s *' % CHILD_SCRIPT_RESULT, + 'parent_script* %s *' % PARENT_SCRIPT_RESULT, + ]) assert result.ret == 0 @@ -291,7 +334,7 @@ def test_dist_subprocess_not_collocated(testdir, tmpdir): dir2 = tmpdir.mkdir('dir2') result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % scripts.dirpath(), + '--cov=%s' % scripts.dirpath(), '--cov-report=term-missing', '--dist=load', '--tx=popen//chdir=%s' % dir1, @@ -302,9 +345,9 @@ def test_dist_subprocess_not_collocated(testdir, tmpdir): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'child_script * %s *' % CHILD_SCRIPT_RESULT, - 'parent_script * %s *' % PARENT_SCRIPT_RESULT, - ]) + 'child_script* %s *' % CHILD_SCRIPT_RESULT, + 'parent_script* %s *' % PARENT_SCRIPT_RESULT, + ]) assert result.ret == 0 @@ -312,14 +355,14 @@ def test_empty_report(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov', '--cov-source=non_existent_module', + '--cov=non_existent_module', '--cov-report=term-missing', script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', '*10 passed*' - ]) + ]) assert result.ret == 0 matching_lines = [line for line in result.outlines if '%' in line] assert not matching_lines @@ -332,10 +375,11 @@ def test_dist_missing_data(testdir): exe = os.path.join(venv_path, 'Scripts', 'python.exe') else: exe = os.path.join(venv_path, 'bin', 'python') + subprocess.check_call([exe, '-mpip' if sys.version_info >= (2, 7) else '-mpip.__main__', 'install', 'py', 'pytest']) script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', '--dist=load', '--tx=popen//python=%s' % exe, @@ -343,7 +387,7 @@ def test_dist_missing_data(testdir): result.stdout.fnmatch_lines([ '*- coverage: failed slaves -*' - ]) + ]) assert result.ret == 0 @@ -351,15 +395,15 @@ def test_funcarg(testdir): script = testdir.makepyfile(SCRIPT_FUNCARG) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_funcarg * 3 * 100%*', + 'test_funcarg* 3 * 100%*', '*1 passed*' - ]) + ]) assert result.ret == 0 @@ -371,7 +415,7 @@ def test_funcarg_not_active(testdir): result.stdout.fnmatch_lines([ '*1 passed*' - ]) + ]) assert result.ret == 0 @@ -381,15 +425,15 @@ def test_multiprocessing_subprocess(testdir): script = testdir.makepyfile(MULTIPROCESSING_SCRIPT) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_multiprocessing_subprocess * 8 * 100%*', + 'test_multiprocessing_subprocess* 8 * 100%*', '*1 passed*' - ]) + ]) assert result.ret == 0 @@ -414,7 +458,7 @@ def test_basic(): ''' -CONF_RESULT = 'mod * 2 * 100% *' +CONF_RESULT = 'mod* 2 * 100% *' def test_cover_conftest(testdir): @@ -422,7 +466,7 @@ def test_cover_conftest(testdir): testdir.makeconftest(CONFTEST) script = testdir.makepyfile(BASIC_TEST) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', script) assert result.ret == 0 @@ -434,7 +478,7 @@ def test_cover_conftest_dist(testdir): testdir.makeconftest(CONFTEST) script = testdir.makepyfile(BASIC_TEST) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', '--dist=load', '--tx=2*popen', @@ -470,11 +514,11 @@ def test_coveragerc(testdir): script = testdir.makepyfile(EXCLUDED_TEST) result = testdir.runpytest('-v', '--cov-config=coveragerc', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', script) assert result.ret == 0 - result.stdout.fnmatch_lines(['test_coveragerc * %s' % EXCLUDED_RESULT]) + result.stdout.fnmatch_lines(['test_coveragerc* %s' % EXCLUDED_RESULT]) def test_coveragerc_dist(testdir): @@ -482,13 +526,13 @@ def test_coveragerc_dist(testdir): script = testdir.makepyfile(EXCLUDED_TEST) result = testdir.runpytest('-v', '--cov-config=coveragerc', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', '-n', '2', script) assert result.ret == 0 result.stdout.fnmatch_lines( - ['test_coveragerc_dist * %s' % EXCLUDED_RESULT]) + ['test_coveragerc_dist* %s' % EXCLUDED_RESULT]) CLEAR_ENVIRON_TEST = ''' @@ -504,7 +548,7 @@ def test_basic(): def test_clear_environ(testdir): script = testdir.makepyfile(CLEAR_ENVIRON_TEST) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=term-missing', script) assert result.ret == 0 @@ -527,42 +571,29 @@ def test_dist_boxed(testdir): script = testdir.makepyfile(SCRIPT_SIMPLE) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--boxed', script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_dist_boxed * %s*' % SCRIPT_SIMPLE_RESULT, + 'test_dist_boxed* %s*' % SCRIPT_SIMPLE_RESULT, '*1 passed*' - ]) + ]) assert result.ret == 0 def test_not_started_plugin_does_not_fail(testdir): - plugin = pytest_cov.CovPlugin(None, None, start=False) + plugin = pytest_cov.plugin.CovPlugin(None, None, start=False) plugin.pytest_sessionfinish(None, None) plugin.pytest_terminal_summary(None) -def test_deprecation_warning(testdir): - script = testdir.makepyfile(SCRIPT) - - result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), - script) - - result.stdout.fnmatch_lines([ - 'Deprecation warning: * --cov-source instead*' - ]) - assert result.ret == 0 - - def test_default_output_setting(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), script) result.stdout.fnmatch_lines([ @@ -575,7 +606,7 @@ def test_disabled_output(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov', '--cov-source=%s' % script.dirpath(), + '--cov=%s' % script.dirpath(), '--cov-report=', script) @@ -588,8 +619,7 @@ def test_coverage_file(testdir): data_file_name = 'covdata' os.environ['COVERAGE_FILE'] = data_file_name try: - result = testdir.runpytest('-v', '--cov', - '--cov-source=%s' % script.dirpath(), + result = testdir.runpytest('-v', '--cov=%s' % script.dirpath(), script) assert result.ret == 0 data_file = testdir.tmpdir.join(data_file_name) diff --git a/tox.ini b/tox.ini index b59374ac..c59abb73 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,72 @@ +; a generative tox configuration, see: https://testrun.org/tox/latest/config.html#generative-envlist + [tox] -envlist = flake8 +envlist = + check, + {2.6,2.7,3.3,3.4,pypy}-{37,40}, + docs + +[testenv] +basepython = + pypy: pypy + 2.6: {env:TOXPYTHON:python2.6} + {2.7,docs}: {env:TOXPYTHON:python2.7} + 3.3: {env:TOXPYTHON:python3.3} + 3.4: {env:TOXPYTHON:python3.4} + {clean,check,report,extension-coveralls,coveralls}: python3.4 +setenv = + PYTHONPATH={toxinidir}/tests + PYTHONUNBUFFERED=yes +passenv = + * +deps = + pytest==2.7.1 + pytest-capturelog + 37: coverage==3.7.1 + 40: coverage==4.0a6 + virtualenv + pytest-xdist==1.12 + pytest-cache==1.0.0 +pip_pre = true + +commands = + {posargs:py.test -vv} +usedevelop = false + +[testenv:spell] +setenv = + SPELLCHECK=1 +commands = + sphinx-build -b spelling docs dist/docs +usedevelop = true +deps = + -r{toxinidir}/docs/requirements.txt + sphinxcontrib-spelling + pyenchant + +[testenv:docs] +whitelist_externals = + rm +commands = + sphinx-build {posargs:-E} -b html docs dist/docs + sphinx-build -b linkcheck docs dist/docs +usedevelop = true +deps = + -r{toxinidir}/docs/requirements.txt + +[testenv:check] +basepython = python3.4 +deps = + docutils + check-manifest + flake8 + readme + pygments +usedevelop = true +commands = + python setup.py check --strict --metadata --restructuredtext + check-manifest {toxinidir} + flake8 src + -[flake8] -max-line-length = 99 -[testenv:flake8] -deps = flake8 -commands = flake8