Skip to content

Commit

Permalink
chore: rename 'pytest_command' to 'python_path'
Browse files Browse the repository at this point in the history
We add 'pytest_command' so that users can specify the pytest command to use.
That is still confusing for users to setup the config. Plus people are more used
to give a python path to execute.

So I think it's good idea to replace 'pytest_command' to the simpler 'python_path'.
  • Loading branch information
giovanni-guidini committed Dec 27, 2023
1 parent e905e58 commit 2585ba5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
14 changes: 6 additions & 8 deletions codecov_cli/runners/pytest_standard_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@

class PytestStandardRunnerConfigParams(dict):
@property
def pytest_command(self) -> List[str]:
command_from_config = self.get("pytest_command")
if isinstance(command_from_config, str):
logger.warning("pytest_command should be a list")
command_from_config = command_from_config.split(" ")
return command_from_config or ["python", "-m", "pytest"]
def python_path(self) -> str:
python_path = self.get("python_path")
return python_path or "python"

@property
def collect_tests_options(self) -> List[str]:
Expand All @@ -49,6 +46,7 @@ def coverage_root(self) -> str:
class PytestStandardRunner(LabelAnalysisRunnerInterface):

dry_run_runner_options = ["--cov-context=test"]
params: PytestStandardRunnerConfigParams

def __init__(self, config_params: Optional[dict] = None) -> None:
super().__init__()
Expand All @@ -70,7 +68,7 @@ def _execute_pytest(self, pytest_args: List[str], capture_output: bool = True):
Raises Exception if pytest fails
Returns the complete pytest output
"""
command = self.params.pytest_command + pytest_args
command = [self.params.python_path, "-m", "pytest"] + pytest_args
try:
result = subprocess.run(
command,
Expand Down Expand Up @@ -101,7 +99,7 @@ def collect_tests(self):
"Collecting tests",
extra=dict(
extra_log_attributes=dict(
pytest_command=self.params.pytest_command,
pytest_command=[self.params.python_path, "-m", "pytest"],
pytest_options=options_to_use,
),
),
Expand Down
12 changes: 4 additions & 8 deletions tests/runners/test_pytest_standard_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,18 @@ def test_execute_pytest(self, mock_subprocess):
)
assert result == output

@pytest.mark.parametrize(
"command_configured", [["pyenv", "pytest"], "pyenv pytest"]
)
@pytest.mark.parametrize("python_path", ["/usr/bin/python", "venv/bin/python"])
@patch("codecov_cli.runners.pytest_standard_runner.subprocess")
def test_execute_pytest_user_provided_command(
self, mock_subprocess, command_configured
):
def test_execute_pytest_user_provided_command(self, mock_subprocess, python_path):
output = "Output in stdout"
return_value = MagicMock(stdout=output.encode("utf-8"))
mock_subprocess.run.return_value = return_value

runner = PytestStandardRunner(dict(pytest_command=command_configured))
runner = PytestStandardRunner(dict(python_path=python_path))

result = runner._execute_pytest(["--option", "--ignore=batata"])
mock_subprocess.run.assert_called_with(
["pyenv", "pytest", "--option", "--ignore=batata"],
[python_path, "-m", "pytest", "--option", "--ignore=batata"],
capture_output=True,
check=True,
stdout=None,
Expand Down

0 comments on commit 2585ba5

Please sign in to comment.