summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2011-11-29 17:02:24 -0500
committerJason R. Coombs <jaraco@jaraco.com>2011-11-29 17:02:24 -0500
commitb1410c2434f959f0faa30020b63f53b761b0a7e1 (patch)
treed422100223a7bc1fd2f027477163cca72dfca8e9
downloadpytest-runner-b1410c2434f959f0faa30020b63f53b761b0a7e1.tar.gz
Adding command
-rw-r--r--command.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/command.py b/command.py
new file mode 100644
index 0000000..c21037c
--- /dev/null
+++ b/command.py
@@ -0,0 +1,54 @@
+"""
+Setup scripts can use this to add setup.py test support for pytest runner.
+
+Recommended usage:
+
+execfile('pytest-runner/command.py')
+setup_params = dict(...)
+PyTest.install(setup_params)
+setuptools.setup(**setup_params)
+"""
+
+from setuptools.command import test as _pytest_runner_test
+
+class PyTest(_pytest_runner_test.test):
+ user_options = [
+ ('junitxml=', None, "Output jUnit XML test results to specified "
+ "file"),
+ ]
+
+ def initialize_options(self):
+ self.junitxml=None
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ if self.distribution.install_requires:
+ self.distribution.fetch_build_eggs(self.distribution.install_requires)
+ if self.distribution.tests_require:
+ self.distribution.fetch_build_eggs(self.distribution.tests_require)
+ if self.dry_run:
+ self.announce('skipping tests (dry run)')
+ return
+ self.with_project_on_sys_path(self.run_tests)
+
+ def run_tests(self):
+ import pytest
+ 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)
+ pytest.main()
+ sys.argv[:] = argv_saved
+
+ @classmethod
+ def install(cls, setup_params):
+ reqs = setup_params.setdefault('tests_require', [])
+ if not any('pytest' in req for req in reqs):
+ reqs.extend(['pytest>=2.1.2',])
+ setup_params.setdefault('cmdclass', {}).update(
+ test=cls,
+ )