diff options
author | Georg Brandl <georg@python.org> | 2014-11-11 10:00:06 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-11-11 10:00:06 +0100 |
commit | 3fcd14a2436594338146b6665fabebbc6bdb3f3d (patch) | |
tree | 58b25395bd46e44f5012292b2106527258076d48 | |
parent | 3ee9b445c73f1ab4ad7be953adf8f229f2a8d76f (diff) | |
download | pygments-3fcd14a2436594338146b6665fabebbc6bdb3f3d.tar.gz |
Do not import pygments prematurely when running with coverage.
-rw-r--r-- | tests/run.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/tests/run.py b/tests/run.py index 94d629e8..c54e0bfa 100644 --- a/tests/run.py +++ b/tests/run.py @@ -28,18 +28,23 @@ except ImportError: print('nose is required to run the Pygments test suite') sys.exit(1) -try: - # make sure the current source is first on sys.path - sys.path.insert(0, '..') - import pygments -except SyntaxError as err: - print('Syntax error: %s' % err) - sys.exit(1) -except ImportError as err: - print('Cannot find Pygments to test: %s' % err) - sys.exit(1) +# make sure the current source is first on sys.path +sys.path.insert(0, '..') + +if '--with-coverage' not in sys.argv: + # if running with coverage, pygments should not be imported before coverage + # is started, otherwise it will count already executed lines as uncovered + try: + import pygments + except ImportError as err: + print('Cannot find Pygments to test: %s' % err) + sys.exit(1) + else: + print('Pygments %s test suite running (Python %s)...' % + (pygments.__version__, sys.version.split()[0]), + file=sys.stderr) else: - print('Pygments %s test suite running (Python %s)...' % - (pygments.__version__, sys.version.split()[0])) + print('Pygments test suite running (Python %s)...' % sys.version.split()[0], + file=sys.stderr) nose.main() |