Force serial hook runs during tests

This commit is contained in:
Chris Kuehl 2018-10-22 09:51:14 -07:00 committed by Chris Kuehl
parent aa50a8cde0
commit 9125439c3a
3 changed files with 13 additions and 3 deletions

View file

@ -50,7 +50,7 @@ def no_install(prefix, version, additional_dependencies):
def target_concurrency(hook): def target_concurrency(hook):
if hook['require_serial']: if hook['require_serial'] or 'PRE_COMMIT_NO_CONCURRENCY' in os.environ:
return 1 return 1
else: else:
# Travis appears to have a bunch of CPUs, but we can't use them all. # Travis appears to have a bunch of CPUs, but we can't use them all.

View file

@ -40,9 +40,17 @@ def test_target_concurrency_normal():
def test_target_concurrency_cpu_count_require_serial_true(): def test_target_concurrency_cpu_count_require_serial_true():
with mock.patch.dict(os.environ, {}, clear=True):
assert helpers.target_concurrency({'require_serial': True}) == 1 assert helpers.target_concurrency({'require_serial': True}) == 1
def test_target_concurrency_testing_env_var():
with mock.patch.dict(
os.environ, {'PRE_COMMIT_NO_CONCURRENCY': '1'}, clear=True,
):
assert helpers.target_concurrency({'require_serial': False}) == 1
def test_target_concurrency_on_travis(): def test_target_concurrency_on_travis():
with mock.patch.dict(os.environ, {'TRAVIS': '1'}, clear=True): with mock.patch.dict(os.environ, {'TRAVIS': '1'}, clear=True):
assert helpers.target_concurrency({'require_serial': False}) == 2 assert helpers.target_concurrency({'require_serial': False}) == 2
@ -52,4 +60,5 @@ def test_target_concurrency_cpu_count_not_implemented():
with mock.patch.object( with mock.patch.object(
multiprocessing, 'cpu_count', side_effect=NotImplementedError, multiprocessing, 'cpu_count', side_effect=NotImplementedError,
): ):
with mock.patch.dict(os.environ, {}, clear=True):
assert helpers.target_concurrency({'require_serial': False}) == 1 assert helpers.target_concurrency({'require_serial': False}) == 1

View file

@ -27,3 +27,4 @@ env =
GIT_AUTHOR_EMAIL=test@example.com GIT_AUTHOR_EMAIL=test@example.com
GIT_COMMITTER_EMAIL=test@example.com GIT_COMMITTER_EMAIL=test@example.com
VIRTUALENV_NO_DOWNLOAD=1 VIRTUALENV_NO_DOWNLOAD=1
PRE_COMMIT_NO_CONCURRENCY=1