Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9125439

Browse files
committed
Force serial hook runs during tests
1 parent aa50a8c commit 9125439

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

pre_commit/languages/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def no_install(prefix, version, additional_dependencies):
5050

5151

5252
def target_concurrency(hook):
53-
if hook['require_serial']:
53+
if hook['require_serial'] or 'PRE_COMMIT_NO_CONCURRENCY' in os.environ:
5454
return 1
5555
else:
5656
# Travis appears to have a bunch of CPUs, but we can't use them all.

tests/languages/helpers_test.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ def test_target_concurrency_normal():
4040

4141

4242
def test_target_concurrency_cpu_count_require_serial_true():
43-
assert helpers.target_concurrency({'require_serial': True}) == 1
43+
with mock.patch.dict(os.environ, {}, clear=True):
44+
assert helpers.target_concurrency({'require_serial': True}) == 1
45+
46+
47+
def test_target_concurrency_testing_env_var():
48+
with mock.patch.dict(
49+
os.environ, {'PRE_COMMIT_NO_CONCURRENCY': '1'}, clear=True,
50+
):
51+
assert helpers.target_concurrency({'require_serial': False}) == 1
4452

4553

4654
def test_target_concurrency_on_travis():
@@ -52,4 +60,5 @@ def test_target_concurrency_cpu_count_not_implemented():
5260
with mock.patch.object(
5361
multiprocessing, 'cpu_count', side_effect=NotImplementedError,
5462
):
55-
assert helpers.target_concurrency({'require_serial': False}) == 1
63+
with mock.patch.dict(os.environ, {}, clear=True):
64+
assert helpers.target_concurrency({'require_serial': False}) == 1

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ env =
2727
GIT_AUTHOR_EMAIL[email protected]
2828
GIT_COMMITTER_EMAIL[email protected]
2929
VIRTUALENV_NO_DOWNLOAD=1
30+
PRE_COMMIT_NO_CONCURRENCY=1

0 commit comments

Comments
 (0)