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
|
||||
----------------------------------------------
|
||||
|
||||
- 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue