respect sys.dont_write_bytecode and PYTHONDONTWRITEBYTECODE
This commit is contained in:
parent
14ceaf2459
commit
3cc8697744
|
@ -1,6 +1,7 @@
|
||||||
Changes between 2.1.0 and 2.1.1.DEV
|
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 assertion rewriting in read-only directories
|
||||||
- fix issue59: provide system-out/err tags for junitxml output
|
- fix issue59: provide system-out/err tags for junitxml output
|
||||||
- fix assertion rewriting on boolean operations with 3 or more operands
|
- fix assertion rewriting on boolean operations with 3 or more operands
|
||||||
|
|
|
@ -89,14 +89,14 @@ class AssertionRewritingHook(object):
|
||||||
# tricky race conditions, we maintain the following invariant: The
|
# tricky race conditions, we maintain the following invariant: The
|
||||||
# cached pyc is always a complete, valid pyc. Operations on it must be
|
# cached pyc is always a complete, valid pyc. Operations on it must be
|
||||||
# atomic. POSIX's atomic rename comes in handy.
|
# atomic. POSIX's atomic rename comes in handy.
|
||||||
|
write = not sys.dont_write_bytecode
|
||||||
cache_dir = os.path.join(fn_pypath.dirname, "__pycache__")
|
cache_dir = os.path.join(fn_pypath.dirname, "__pycache__")
|
||||||
try:
|
if write:
|
||||||
py.path.local(cache_dir).ensure(dir=True)
|
try:
|
||||||
except py.error.EACCES:
|
py.path.local(cache_dir).ensure(dir=True)
|
||||||
state.trace("read only directory: %r" % (fn_pypath.dirname,))
|
except py.error.EACCES:
|
||||||
write = False
|
state.trace("read only directory: %r" % (fn_pypath.dirname,))
|
||||||
else:
|
write = False
|
||||||
write = True
|
|
||||||
cache_name = fn_pypath.basename[:-3] + "." + PYTEST_TAG + ".pyc"
|
cache_name = fn_pypath.basename[:-3] + "." + PYTEST_TAG + ".pyc"
|
||||||
pyc = os.path.join(cache_dir, cache_name)
|
pyc = os.path.join(cache_dir, cache_name)
|
||||||
# Notice that even if we're in a read-only directory, I'm going to check
|
# Notice that even if we're in a read-only directory, I'm going to check
|
||||||
|
|
|
@ -277,3 +277,13 @@ def test_rewritten():
|
||||||
assert "@py_builtins" in globals()""")
|
assert "@py_builtins" in globals()""")
|
||||||
sub.chmod(320)
|
sub.chmod(320)
|
||||||
assert testdir.runpytest().ret == 0
|
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
|
||||||
|
|
Loading…
Reference in New Issue