Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 62abfb1

Browse files
Make PythonStandardRunner include curr dir by default (#133)
Turns out that when you package the CLI in PyInstaller, if you don't have the curr dir in PATH there's a high probability that pytest will fail because of the pytest plugins (it won't find them) So it's better to add the current dir by default to avoid issues. On top of that also adding `params` in the runner interface so we can log the params of the selected runner.
1 parent 92f32e5 commit 62abfb1

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

codecov_cli/commands/labelanalysis.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ def label_analysis(
5656
codecov_yaml = ctx.obj["codecov_yaml"] or {}
5757
cli_config = codecov_yaml.get("cli", {})
5858
runner = get_runner(cli_config, runner_name)
59-
logger.debug(f"Selected runner: {runner}")
59+
logger.debug(
60+
f"Selected runner: {runner}",
61+
extra=dict(extra_log_attributes=dict(config=runner.params)),
62+
)
6063
requested_labels = runner.collect_tests()
6164
logger.info(f"Collected {len(requested_labels)} tests")
6265
logger.debug(

codecov_cli/runners/python_standard_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, config_params: PythonStandardRunnerConfigParams = None) -> No
4242
super().__init__()
4343
default_config: PythonStandardRunnerConfigParams = {
4444
"collect_tests_options": [],
45-
"include_curr_dir": False,
45+
"include_curr_dir": True,
4646
}
4747
if config_params is None:
4848
config_params = PythonStandardRunnerConfigParams()

codecov_cli/runners/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class LabelAnalysisRequestResult(TypedDict):
99

1010

1111
class LabelAnalysisRunnerInterface(object):
12+
params = None
13+
1214
def collect_tests(self) -> List[str]:
1315
raise NotImplementedError()
1416

tests/runners/test_python_standard_runner.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@ class TestPythonStandardRunner(object):
1616

1717
def test_init_with_params(self):
1818
assert self.runner.params == PythonStandardRunnerConfigParams(
19-
collect_tests_options=[], include_curr_dir=False
19+
collect_tests_options=[], include_curr_dir=True
2020
)
2121
config_params = PythonStandardRunnerConfigParams(
2222
collect_tests_options=["--option=value", "-option"], include_curr_dir=True
2323
)
2424
runner_with_params = PythonStandardRunner(config_params)
2525
assert runner_with_params.params == config_params
2626

27+
@patch(
28+
"codecov_cli.runners.python_standard_runner.getcwd",
29+
return_value="current directory",
30+
)
2731
@patch("codecov_cli.runners.python_standard_runner.path")
2832
@patch("codecov_cli.runners.python_standard_runner.StringIO")
2933
@patch("codecov_cli.runners.python_standard_runner.pytest")
30-
def test_execute_pytest(self, mock_pytest, mock_stringio, mock_sys_path):
34+
def test_execute_pytest(
35+
self, mock_pytest, mock_stringio, mock_sys_path, mock_getcwd
36+
):
3137
output = "Output in stdout"
3238
mock_getvalue = MagicMock(return_value=output)
3339
mock_stringio.return_value.__enter__.return_value.getvalue = mock_getvalue
@@ -37,13 +43,20 @@ def test_execute_pytest(self, mock_pytest, mock_stringio, mock_sys_path):
3743
mock_pytest.main.assert_called_with(["--option", "--ignore=batata"])
3844
mock_stringio.assert_called()
3945
mock_getvalue.assert_called()
40-
mock_sys_path.append.assert_not_called()
46+
mock_sys_path.append.assert_called_with("current directory")
47+
mock_sys_path.remove.assert_called_with("current directory")
4148
assert result == output
4249

50+
@patch(
51+
"codecov_cli.runners.python_standard_runner.getcwd",
52+
return_value="current directory",
53+
)
4354
@patch("codecov_cli.runners.python_standard_runner.path")
4455
@patch("codecov_cli.runners.python_standard_runner.StringIO")
4556
@patch("codecov_cli.runners.python_standard_runner.pytest")
46-
def test_execute_pytest_fail(self, mock_pytest, mock_stringio, mock_sys_path):
57+
def test_execute_pytest_fail(
58+
self, mock_pytest, mock_stringio, mock_sys_path, mock_getcwd
59+
):
4760
output = "Output in stdout"
4861
mock_getvalue = MagicMock(return_value=output)
4962
mock_stringio.return_value.__enter__.return_value.getvalue = mock_getvalue
@@ -55,13 +68,13 @@ def test_execute_pytest_fail(self, mock_pytest, mock_stringio, mock_sys_path):
5568
mock_pytest.main.assert_called_with(["--option", "--ignore=batata"])
5669
mock_stringio.assert_called()
5770
mock_getvalue.assert_called()
58-
mock_sys_path.append.assert_not_called()
71+
mock_sys_path.append.assert_called_with("current directory")
5972

6073
@patch("codecov_cli.runners.python_standard_runner.getcwd")
6174
@patch("codecov_cli.runners.python_standard_runner.path")
6275
@patch("codecov_cli.runners.python_standard_runner.StringIO")
6376
@patch("codecov_cli.runners.python_standard_runner.pytest")
64-
def test_execute_pytest_include_curr_dir(
77+
def test_execute_pytest_NOT_include_curr_dir(
6578
self, mock_pytest, mock_stringio, mock_sys_path, mock_getcwd
6679
):
6780
output = "Output in stdout"
@@ -70,14 +83,13 @@ def test_execute_pytest_include_curr_dir(
7083
mock_stringio.return_value.__enter__.return_value.getvalue = mock_getvalue
7184
mock_pytest.main.return_value = ExitCode.OK
7285

73-
config_params = PythonStandardRunnerConfigParams(include_curr_dir=True)
86+
config_params = PythonStandardRunnerConfigParams(include_curr_dir=False)
7487
runner = PythonStandardRunner(config_params)
7588
result = runner._execute_pytest(["--option", "--ignore=batata"])
7689
mock_pytest.main.assert_called_with(["--option", "--ignore=batata"])
7790
mock_stringio.assert_called()
7891
mock_getvalue.assert_called()
79-
mock_sys_path.append.assert_called_with("current directory")
80-
mock_sys_path.remove.assert_called_with("current directory")
92+
mock_sys_path.append.assert_not_called()
8193
mock_getcwd.assert_called()
8294
assert result == output
8395

tests/runners/test_runners.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_python_standard_runner_with_options(self):
1717
)
1818
runner_instance = get_runner({"runners": {"python": config_params}}, "python")
1919
assert isinstance(runner_instance, PythonStandardRunner)
20-
assert runner_instance.params == {**config_params, "include_curr_dir": False}
20+
assert runner_instance.params == {**config_params, "include_curr_dir": True}
2121

2222
def test_get_dan_runner_with_params(self):
2323
config = {

0 commit comments

Comments
 (0)