From 1aca6c9d7cd50cd726222ced084658f955a1adc1 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sat, 7 Jul 2012 16:09:53 +0200 Subject: [PATCH] Fix extension of of cached re-written file With PYTHONOPTIMIZE set this had the extension of "o" instead of ".pyo". Fixes issue #168. --- _pytest/assertion/rewrite.py | 2 +- testing/test_assertrewrite.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index a67324885..f6f67609f 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -34,7 +34,7 @@ else: PYTEST_TAG = "%s-%s%s-PYTEST" % (impl, ver[0], ver[1]) del ver, impl -PYC_EXT = ".py" + "c" if __debug__ else "o" +PYC_EXT = ".py" + ("c" if __debug__ else "o") PYC_TAIL = "." + PYTEST_TAG + PYC_EXT REWRITE_NEWLINES = sys.version_info[:2] != (2, 7) and sys.version_info < (3, 2) diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 74d29768d..a5a197ae3 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -1,3 +1,4 @@ +import os import sys import zipfile import py @@ -352,6 +353,7 @@ def test_no_bytecode(): @pytest.mark.skipif('"__pypy__" in sys.modules') def test_pyc_vs_pyo(self, testdir, monkeypatch): + import _pytest.assertion.rewrite testdir.makepyfile(""" import pytest def test_optimized(): @@ -362,8 +364,12 @@ def test_optimized(): tmp = "--basetemp=%s" % p monkeypatch.setenv("PYTHONOPTIMIZE", "2") assert testdir.runpybin("py.test", tmp).ret == 0 + fname = 'test_pyc_vs_pyo.%s.pyo' % _pytest.assertion.rewrite.PYTEST_TAG + assert fname in os.listdir('__pycache__') monkeypatch.undo() assert testdir.runpybin("py.test", tmp).ret == 1 + fname = 'test_pyc_vs_pyo.%s.pyc' % _pytest.assertion.rewrite.PYTEST_TAG + assert fname in os.listdir('__pycache__') def test_package(self, testdir): pkg = testdir.tmpdir.join("pkg")