From c56da21c98aca5d2f049948f9b00e3b44908be66 Mon Sep 17 00:00:00 2001 From: ofekisr <35701650+ofekisr@users.noreply.github.com> Date: Wed, 29 Dec 2021 17:54:12 +0200 Subject: [PATCH] fix: tests can failed on different order executions (#17885) --- .../charts/data/api_tests.py | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tests/integration_tests/charts/data/api_tests.py b/tests/integration_tests/charts/data/api_tests.py index 1e6aa5601d034..efe751c895312 100644 --- a/tests/integration_tests/charts/data/api_tests.py +++ b/tests/integration_tests/charts/data/api_tests.py @@ -126,23 +126,25 @@ def assert_row_count(rv: Response, expected_row_count: int): assert rv.json["result"][0]["rowcount"] == expected_row_count @pytest.mark.usefixtures("load_birth_names_dashboard_with_slices") + @mock.patch( + "superset.common.query_context_factory.config", {**app.config, "ROW_LIMIT": 7}, + ) def test_without_row_limit__row_count_as_default_row_limit(self): # arrange - row_limit_before = app.config["ROW_LIMIT"] expected_row_count = 7 - app.config["ROW_LIMIT"] = expected_row_count del self.query_context_payload["queries"][0]["row_limit"] # act rv = self.post_assert_metric(CHART_DATA_URI, self.query_context_payload, "data") # assert self.assert_row_count(rv, expected_row_count) - # cleanup - app.config["ROW_LIMIT"] = row_limit_before @pytest.mark.usefixtures("load_birth_names_dashboard_with_slices") + @mock.patch( + "superset.common.query_context_factory.config", + {**app.config, "SAMPLES_ROW_LIMIT": 5}, + ) def test_as_samples_without_row_limit__row_count_as_default_samples_row_limit(self): # arrange - samples_row_limit_before = app.config["SAMPLES_ROW_LIMIT"] expected_row_count = 5 app.config["SAMPLES_ROW_LIMIT"] = expected_row_count self.query_context_payload["result_type"] = ChartDataResultType.SAMPLES @@ -154,15 +156,13 @@ def test_as_samples_without_row_limit__row_count_as_default_samples_row_limit(se # assert self.assert_row_count(rv, expected_row_count) - # cleanup - app.config["SAMPLES_ROW_LIMIT"] = samples_row_limit_before - @pytest.mark.usefixtures("load_birth_names_dashboard_with_slices") + @mock.patch( + "superset.utils.core.current_app.config", {**app.config, "SQL_MAX_ROW": 10}, + ) def test_with_row_limit_bigger_then_sql_max_row__rowcount_as_sql_max_row(self): # arrange expected_row_count = 10 - max_row_before = app.config["SQL_MAX_ROW"] - app.config["SQL_MAX_ROW"] = expected_row_count self.query_context_payload["queries"][0]["row_limit"] = 10000000 # act @@ -171,9 +171,6 @@ def test_with_row_limit_bigger_then_sql_max_row__rowcount_as_sql_max_row(self): # assert self.assert_row_count(rv, expected_row_count) - # cleanup - app.config["SQL_MAX_ROW"] = max_row_before - @pytest.mark.usefixtures("load_birth_names_dashboard_with_slices") @mock.patch( "superset.utils.core.current_app.config", {**app.config, "SQL_MAX_ROW": 5},