Skip to content

Commit 30ecec1

Browse files
committed
Update ZenUnitDevOpsPython flake8 command line argument from '-j 61' to '-j {multiprocessing.cpu_count()}'
1 parent 7515fec commit 30ecec1

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

ZenUnitDevOpsPython/Python.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import glob
2+
import multiprocessing
23
import os
34
import platform
45
import sys
@@ -11,6 +12,11 @@ def pylint_file(pythonFilePath: str) -> int:
1112
pylintExitCode = Process.run_and_get_exit_code(pylintCommand)
1213
return pylintExitCode
1314

15+
def run_flake8() -> None:
16+
cpuCount = multiprocessing.cpu_count()
17+
flake8Command = f'flake8 -j {cpuCount} --config=.flake8 --show-source --benchmark'
18+
Process.fail_fast_run(flake8Command)
19+
1420
def run_mypy() -> None:
1521
Process.fail_fast_run('mypy .')
1622

@@ -24,10 +30,6 @@ def run_pylint_on_all_files_in_parallel() -> None:
2430
if not allPylintsSucceeded:
2531
sys.exit(1)
2632

27-
def run_flake8() -> None:
28-
flake8Command = 'flake8 -j 61 --config=.flake8 --show-source --benchmark'
29-
Process.fail_fast_run(flake8Command)
30-
3133
def run_all_with_coverage(testsProjectName: str, omitPattern: str) -> None:
3234
print(f'Running {testsProjectName}/RunAll.py with coverage from', os.getcwd())
3335
Process.fail_fast_run(f'coverage run --branch {testsProjectName}/RunAll.py')

ZenUnitDevOpsPythonTests/PythonTests.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import glob
2+
import multiprocessing
23
import os
34
import platform
45
import sys
@@ -9,9 +10,9 @@
910

1011
testNames = [
1112
'test_pylint_file_CallsPylintOnAllPythonFilesInCurrentFolderAndSubFolders',
13+
'test_run_flake8_RunsFlake8WithFlake8Config',
1214
'test_run_mypy_RunsMypyDot',
1315
'test_run_pylint_on_all_files_in_parallel_LinuxCallsMapParallelPylintFileWithAllPyFilePaths_WindowsCallsMapSequential',
14-
'test_run_flake8_RunsFlake8WithFlake8Config',
1516
'test_run_all_with_coverage_RunsCoverage_RunsReport_RunsHtml_RunsXml_ExitsWithReportExitCode'
1617
]
1718

@@ -30,6 +31,18 @@ def test_pylint_file_CallsPylintOnAllPythonFilesInCurrentFolderAndSubFolders(sel
3031
Process.run_and_get_exit_code.assert_called_once_with(PythonTests.ExpectedPylintCommand + pythonFilePath)
3132
self.assertEqual(pylintExitCode, pylintExitCode)
3233

34+
@staticmethod
35+
@patch('ZenUnitDevOpsPython.Process.fail_fast_run', spec_set=True)
36+
@patch('multiprocessing.cpu_count', spec_set=True)
37+
def test_run_flake8_RunsFlake8WithFlake8Config(_1, _2):
38+
cpuCount = Random.integer()
39+
multiprocessing.cpu_count.return_value = cpuCount
40+
#
41+
Python.run_flake8()
42+
#
43+
expectedFlake8Command = f'flake8 -j {cpuCount} --config=.flake8 --show-source --benchmark'
44+
Process.fail_fast_run.assert_called_once_with(expectedFlake8Command)
45+
3346
@staticmethod
3447
@patch('ZenUnitDevOpsPython.Process.fail_fast_run', spec_set=True)
3548
def test_run_mypy_RunsMypyDot(_1):
@@ -72,15 +85,6 @@ def testcase(platformSystem, expectedMapParallel, allPylintsSucceeded, expectSys
7285
testcase('Windows', False, False, True)
7386
testcase('windows', True, False, True)
7487

75-
@staticmethod
76-
@patch('ZenUnitDevOpsPython.Process.fail_fast_run', spec_set=True)
77-
def test_run_flake8_RunsFlake8WithFlake8Config(_1):
78-
#
79-
Python.run_flake8()
80-
#
81-
expectedFlake8Command = 'flake8 -j 61 --config=.flake8 --show-source --benchmark'
82-
Process.fail_fast_run.assert_called_once_with(expectedFlake8Command)
83-
8488
def test_run_all_with_coverage_RunsCoverage_RunsReport_RunsHtml_RunsXml_ExitsWithReportExitCode(self):
8589
@patch('os.getcwd', spec_set=True)
8690
@patch('ZenUnitDevOpsPython.Process.fail_fast_run', spec_set=True)

ZenUnitDevOpsPythonTests/ZenUnitDevOpsPythonTests.pyproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ProjectGuid>5be2bd06-b3d6-4e12-9d37-cb82aa0ef9d3</ProjectGuid>
77
<ProjectHome>
88
</ProjectHome>
9-
<StartupFile>RunAll.py</StartupFile>
9+
<StartupFile>PythonTests.py</StartupFile>
1010
<SearchPath>..\</SearchPath>
1111
<WorkingDirectory>..</WorkingDirectory>
1212
<OutputPath>.</OutputPath>

0 commit comments

Comments
 (0)