From d702f4da149d9ac9d00f509e214bb2390949fab5 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 14 Aug 2009 09:16:40 -0500 Subject: [PATCH] add a --version option to print the pylib version --HG-- branch : 1.0.x --- CHANGELOG | 6 ++++-- py/test/plugin/pytest_default.py | 8 ++++++++ py/test/testing/acceptance_test.py | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index fa06cb3a8..9c5547029 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,14 +11,16 @@ Changes between 1.0.0 and 1.0.1 was adapted and somewhat unified between windows and linux * fix issue #27: better reporting on non-collectable items given on commandline - (e.g. pyc files) + (e.g. pyc files) + +* fix issue #33: added --version flag (thanks Benjamin Peterson) * "Test" prefixed classes are *not* collected by default anymore if they have an __init__ method * monkeypatch setenv() now accepts a "prepend" parameter -* terser reporting of collection error tracebacks +* improved reporting of collection error tracebacks * simplified multicall mechanism and plugin architecture, renamed some internal methods and argnames diff --git a/py/test/plugin/pytest_default.py b/py/test/plugin/pytest_default.py index 684d1b020..047ea82ca 100644 --- a/py/test/plugin/pytest_default.py +++ b/py/test/plugin/pytest_default.py @@ -1,5 +1,6 @@ """ default hooks and general py.test options. """ +import sys import py def pytest_pyfunc_call(__multicall__, pyfuncitem): @@ -90,10 +91,17 @@ def pytest_addoption(parser): help="shortcut for '--dist=load --tx=NUM*popen'") group.addoption('--rsyncdir', action="append", default=[], metavar="dir1", help="add directory for rsyncing to remote tx nodes.") + group.addoption('--version', action="store_true", + help="display version information") def pytest_configure(config): fixoptions(config) setsession(config) + if config.option.version: + p = py.path.local(py.__file__).dirpath() + print "This is py.test version %s, imported from %s" % ( + py.__version__, p) + sys.exit(0) #xxxloadplugins(config) def fixoptions(config): diff --git a/py/test/testing/acceptance_test.py b/py/test/testing/acceptance_test.py index c96c65185..ae1c42f74 100644 --- a/py/test/testing/acceptance_test.py +++ b/py/test/testing/acceptance_test.py @@ -3,6 +3,14 @@ import py EXPECTTIMEOUT=10.0 class TestGeneralUsage: + def test_version(self, testdir): + assert py.version == py.__version__ + result = testdir.runpytest("--version") + assert result.ret == 0 + p = py.path.local(py.__file__).dirpath() + assert result.stderr.fnmatch_lines([ + '*py.test*%s*, imported from: %s*' % (py.version, p) + ]) def test_config_error(self, testdir): testdir.makeconftest(""" def pytest_configure(config):