From 9125439c3a6b7549bcf6d82c36fc2b89d1283cb2 Mon Sep 17 00:00:00 2001 From: Chris Kuehl Date: Mon, 22 Oct 2018 09:51:14 -0700 Subject: [PATCH] Force serial hook runs during tests --- pre_commit/languages/helpers.py | 2 +- tests/languages/helpers_test.py | 13 +++++++++++-- tox.ini | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pre_commit/languages/helpers.py b/pre_commit/languages/helpers.py index abd28fa0..8b3e590d 100644 --- a/pre_commit/languages/helpers.py +++ b/pre_commit/languages/helpers.py @@ -50,7 +50,7 @@ def no_install(prefix, version, additional_dependencies): def target_concurrency(hook): - if hook['require_serial']: + if hook['require_serial'] or 'PRE_COMMIT_NO_CONCURRENCY' in os.environ: return 1 else: # Travis appears to have a bunch of CPUs, but we can't use them all. diff --git a/tests/languages/helpers_test.py b/tests/languages/helpers_test.py index f1c1497f..e7bd4702 100644 --- a/tests/languages/helpers_test.py +++ b/tests/languages/helpers_test.py @@ -40,7 +40,15 @@ def test_target_concurrency_normal(): def test_target_concurrency_cpu_count_require_serial_true(): - assert helpers.target_concurrency({'require_serial': True}) == 1 + with mock.patch.dict(os.environ, {}, clear=True): + 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(): @@ -52,4 +60,5 @@ def test_target_concurrency_cpu_count_not_implemented(): with mock.patch.object( multiprocessing, 'cpu_count', side_effect=NotImplementedError, ): - assert helpers.target_concurrency({'require_serial': False}) == 1 + with mock.patch.dict(os.environ, {}, clear=True): + assert helpers.target_concurrency({'require_serial': False}) == 1 diff --git a/tox.ini b/tox.ini index d4b590bf..52f3d3ee 100644 --- a/tox.ini +++ b/tox.ini @@ -27,3 +27,4 @@ env = GIT_AUTHOR_EMAIL=test@example.com GIT_COMMITTER_EMAIL=test@example.com VIRTUALENV_NO_DOWNLOAD=1 + PRE_COMMIT_NO_CONCURRENCY=1