From de551c6cf7e79e7f8b4c7948302d4549cc2245c2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 7 Sep 2012 16:29:25 -0400 Subject: Added support for --addopts to ptr command --- README | 22 +++++++++++++++------- ptr.py | 18 ++++++++++++++---- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/README b/README index 12f9046..c72e057 100644 --- a/README +++ b/README @@ -7,27 +7,35 @@ runner. Recommended usage ----------------- -- add 'pytest-runner' to your 'setup_requires' -- include 'pytest' and any other testing requirements to 'tests_require' -- invoke tests with setup.py ptr +- Add 'pytest-runner' to your 'setup_requires'. Pin to '>=1.0,<2.0dev' (or + similar) to avoid pulling in incompatible versions. +- Include 'pytest' and any other testing requirements to 'tests_require'. +- Invoke tests with `setup.py ptr`. Alternate usage --------------- -- include this file (ptr.py) in your repo -- add these lines to your setup.py:: +- Include the file `ptr.py` in your repo. +- Add these lines to your setup.py:: execfile('ptr.py') setup_params = PyTest.install(dict(...)) setuptools.setup(**setup_params) - Where '...' are your normal keyword parameters to setup() + Where '...' are your normal keyword parameters to setup(). -- invoke your tests with setup.py test +- Invoke your tests with setup.py test. Changes ------- +1.1 +~~~ + +* Added support for --addopts to pass any arguments through to py.test. +* Deprecated support for --junitxml. Use --addopts instead. --junitxml will be + removed in 2.0. + 1.0 ~~~ diff --git a/ptr.py b/ptr.py index 5f70a03..4cea126 100644 --- a/ptr.py +++ b/ptr.py @@ -3,6 +3,8 @@ Implementation """ import os as _os +import shlex as _shlex +import warnings as _warnings import setuptools.command.test as _pytest_runner_test @@ -15,6 +17,8 @@ class PyTest(_pytest_runner_test.test): "dependencies"), ('allow-hosts=', None, "Whitelist of comma-separated hosts to allow " "when retrieving dependencies"), + ('addopts=', None, "Additional options to be passed verbatim to the " + "pytest runner") ] def initialize_options(self): @@ -22,9 +26,17 @@ class PyTest(_pytest_runner_test.test): self.extras = False self.index_url = None self.allow_hosts = None + self.addopts = [] def finalize_options(self): - pass + if self.addopts: + self.addopts = _shlex.split(self.addopts) + if self.junitxml: + # For compatibility, allow junitxml to be provided to the plugin. + # In the future, junitxml should be specified using addopts. + _warnings.warn("junitxml is deprecated, use addopts to pass " + "options to py.test", DeprecationWarning) + self.addopts.extend(['--junitxml', self.junitxml]) def run(self): """ @@ -86,9 +98,7 @@ class PyTest(_pytest_runner_test.test): import sys # hide command-line arguments from pytest.main argv_saved = list(sys.argv) - del sys.argv[1:] - if getattr(self, 'junitxml', None): - sys.argv.append('--junitxml=%s' % self.junitxml) + sys.argv[1:] = self.addopts self.result_code = pytest.main() sys.argv[:] = argv_saved -- cgit v1.2.1