Skip to content

Commit

Permalink
TST: make compatible with Python 2 .pyc caching timing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pv committed Sep 19, 2018
1 parent 43bf53e commit ca63acc
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions test/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,19 @@ def test_forkserver(tmpdir):
reason="test requires fork and unix sockets")


def clear_pyc(path):
for fn in os.listdir(path):
fn = join(path, fn)
if not os.path.isfile(fn):
continue
if fn.lower().endswith('.pyc'):
os.unlink(fn)

dn = join(path, '__pycache__')
if os.path.isdir(dn):
shutil.rmtree(dn)


@needs_unix_socket_mark
def test_forkserver_preimport(tmpdir):
tmpdir = six.text_type(tmpdir)
Expand Down Expand Up @@ -302,13 +315,16 @@ def test_forkserver_preimport(tmpdir):
assert success == True
assert out.rstrip() == "message"


#
# Benchmark suite that crashes the forkserver
#

# NOTE: the .pyc files need to be removed, as Python 2 pyc caching
# has problems with overwriting files rapidly
clear_pyc('benchmark')

with open(os.path.join('benchmark', '__init__.py'), 'w') as f:
f.write("import os, sys; print('message'); sys.stdout.flush(); os._exit(0)")
f.write("import os, sys; print('egassem'); sys.stdout.flush(); os._exit(0)")

spawner = runner.ForkServer(env, os.path.abspath('benchmark'))
try:
Expand All @@ -323,6 +339,8 @@ def test_forkserver_preimport(tmpdir):
# Benchmark suite that has an unimportable file
#

clear_pyc('benchmark')

with open(os.path.join('benchmark', '__init__.py'), 'w') as f:
pass

Expand Down Expand Up @@ -380,6 +398,8 @@ def test_run_import_failure(capsys, benchmarks_fixture, launch_method):
# Module with import crashing the process
#

clear_pyc('benchmark')

with open(os.path.join('benchmark', 'unimportable.py'), 'w') as f:
f.write('import sys; sys.stderr.write("hello import"); sys.stderr.flush()\n')
f.write('import os; os._exit(0)')
Expand All @@ -398,6 +418,8 @@ def test_run_import_failure(capsys, benchmarks_fixture, launch_method):
# Module with import printing output
#

clear_pyc('benchmark')

with open(os.path.join('benchmark', 'unimportable.py'), 'w') as f:
f.write('import sys; sys.stderr.write("hello import"); sys.stderr.flush()\n')

Expand Down

0 comments on commit ca63acc

Please sign in to comment.