diff --git a/CHANGELOG b/CHANGELOG index 1dd4a711c..eeb39b211 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Changes between 2.1.0 and 2.1.1.DEV ---------------------------------------------- +- don't cache rewritten modules if bytecode generation is disabled - fix assertion rewriting in read-only directories - fix issue59: provide system-out/err tags for junitxml output - fix assertion rewriting on boolean operations with 3 or more operands diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 1085b761c..34e119db6 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -89,14 +89,14 @@ class AssertionRewritingHook(object): # tricky race conditions, we maintain the following invariant: The # cached pyc is always a complete, valid pyc. Operations on it must be # atomic. POSIX's atomic rename comes in handy. + write = not sys.dont_write_bytecode cache_dir = os.path.join(fn_pypath.dirname, "__pycache__") - try: - py.path.local(cache_dir).ensure(dir=True) - except py.error.EACCES: - state.trace("read only directory: %r" % (fn_pypath.dirname,)) - write = False - else: - write = True + if write: + try: + py.path.local(cache_dir).ensure(dir=True) + except py.error.EACCES: + state.trace("read only directory: %r" % (fn_pypath.dirname,)) + write = False cache_name = fn_pypath.basename[:-3] + "." + PYTEST_TAG + ".pyc" pyc = os.path.join(cache_dir, cache_name) # Notice that even if we're in a read-only directory, I'm going to check diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index ec95f6668..fc1872102 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -277,3 +277,13 @@ def test_rewritten(): assert "@py_builtins" in globals()""") sub.chmod(320) assert testdir.runpytest().ret == 0 + + def test_dont_write_bytecode(self, testdir, monkeypatch): + testdir.makepyfile(""" +import os +def test_no_bytecode(): + assert "__pycache__" in __cached__ + assert not os.path.exists(__cached__) + assert not os.path.exists(os.path.dirname(__cached__))""") + monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1") + assert testdir.runpytest().ret == 0