From 3638b2ec0c385a73b5a15ff8dead8b2af2c7098b Mon Sep 17 00:00:00 2001 From: Giovanni M Guidini <99758426+giovanni-guidini@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:17:14 +0200 Subject: [PATCH] chore: fix test asserts (#407) Changing wrong asserts in tests to the correct function. This would break in python 3.12, but we don't build the CLI for 3.12 (yet) --- tests/runners/test_pytest_standard_runner.py | 2 +- tests/services/static_analysis/test_analyse_file.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/runners/test_pytest_standard_runner.py b/tests/runners/test_pytest_standard_runner.py index aadbcd3f..489a0e0c 100644 --- a/tests/runners/test_pytest_standard_runner.py +++ b/tests/runners/test_pytest_standard_runner.py @@ -55,7 +55,7 @@ def test_warning_bad_config(self, mock_warning): ) runner = PytestStandardRunner(params) # Adding invalid config options emits a warning - assert mock_warning.called_with( + mock_warning.assert_called_with( "Config parameter 'some_missing_option' is unknonw." ) # Warnings don't change the config diff --git a/tests/services/static_analysis/test_analyse_file.py b/tests/services/static_analysis/test_analyse_file.py index 2b28397e..7a31e864 100644 --- a/tests/services/static_analysis/test_analyse_file.py +++ b/tests/services/static_analysis/test_analyse_file.py @@ -47,12 +47,12 @@ def test_sample_analysis(input_filename, output_filename): @patch("builtins.open") @patch("codecov_cli.services.staticanalysis.get_best_analyzer", return_value=None) -def test_analyse_file_no_analyser(mock_get_analyser, mock_open): - fake_contents = MagicMock() +def test_analyse_file_no_analyzer(mock_get_analyzer, mock_open): + fake_contents = MagicMock(name="fake_file_contents") file_name = MagicMock(actual_filepath="filepath") - mock_open.return_value.read.return_value = fake_contents + mock_open.return_value.__enter__.return_value.read.return_value = fake_contents config = {} res = analyze_file(config, file_name) assert res == None - assert mock_open.called_with("filepath", "rb") - assert mock_get_analyser.called_with(file_name, fake_contents) + mock_open.assert_called_with("filepath", "rb") + mock_get_analyzer.assert_called_with(file_name, fake_contents)