Skip to content

Commit 6dc4a83

Browse files
committed
Switch to pytest-rerunfailures to see if that helps
1 parent 053d2ce commit 6dc4a83

File tree

3 files changed

+19
-89
lines changed

3 files changed

+19
-89
lines changed

Makefile

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ dbt-test:
138138
pytest -n auto -m "dbt and not cicdonly"
139139

140140
dbt-fast-test:
141-
pytest -n auto -m "dbt and fast" --retries 3
141+
pytest -n auto -m "dbt and fast" --reruns 3
142142

143143
github-test:
144144
pytest -n auto -m "github"
@@ -173,58 +173,58 @@ engine-%-down:
173173
##################
174174

175175
clickhouse-test: engine-clickhouse-up
176-
pytest -n auto -m "clickhouse" --retries 3 --junitxml=test-results/junit-clickhouse.xml
176+
pytest -n auto -m "clickhouse" --reruns 3 --junitxml=test-results/junit-clickhouse.xml
177177

178178
duckdb-test: engine-duckdb-install
179-
pytest -n auto -m "duckdb" --retries 3 --junitxml=test-results/junit-duckdb.xml
179+
pytest -n auto -m "duckdb" --reruns 3 --junitxml=test-results/junit-duckdb.xml
180180

181181
mssql-test: engine-mssql-up
182-
pytest -n auto -m "mssql" --retries 3 --junitxml=test-results/junit-mssql.xml
182+
pytest -n auto -m "mssql" --reruns 3 --junitxml=test-results/junit-mssql.xml
183183

184184
mysql-test: engine-mysql-up
185-
pytest -n auto -m "mysql" --retries 3 --junitxml=test-results/junit-mysql.xml
185+
pytest -n auto -m "mysql" --reruns 3 --junitxml=test-results/junit-mysql.xml
186186

187187
postgres-test: engine-postgres-up
188-
pytest -n auto -m "postgres" --retries 3 --junitxml=test-results/junit-postgres.xml
188+
pytest -n auto -m "postgres" --reruns 3 --junitxml=test-results/junit-postgres.xml
189189

190190
spark-test: engine-spark-up
191-
pytest -n auto -m "spark" --retries 3 --junitxml=test-results/junit-spark.xml && pytest -n auto -m "pyspark" --retries 3 --junitxml=test-results/junit-pyspark.xml
191+
pytest -n auto -m "spark" --reruns 3 --junitxml=test-results/junit-spark.xml && pytest -n auto -m "pyspark" --reruns 3 --junitxml=test-results/junit-pyspark.xml
192192

193193
trino-test: engine-trino-up
194-
pytest -n auto -m "trino" --retries 3 --junitxml=test-results/junit-trino.xml
194+
pytest -n auto -m "trino" --reruns 3 --junitxml=test-results/junit-trino.xml
195195

196196
risingwave-test: engine-risingwave-up
197-
pytest -n auto -m "risingwave" --retries 3 --junitxml=test-results/junit-risingwave.xml
197+
pytest -n auto -m "risingwave" --reruns 3 --junitxml=test-results/junit-risingwave.xml
198198

199199
#################
200200
# Cloud Engines #
201201
#################
202202

203203
snowflake-test: guard-SNOWFLAKE_ACCOUNT guard-SNOWFLAKE_WAREHOUSE guard-SNOWFLAKE_DATABASE guard-SNOWFLAKE_USER guard-SNOWFLAKE_PASSWORD engine-snowflake-install
204-
pytest -n auto -m "snowflake" --retries 3 --junitxml=test-results/junit-snowflake.xml
204+
pytest -n auto -m "snowflake" --reruns 3 --junitxml=test-results/junit-snowflake.xml
205205

206206
bigquery-test: guard-BIGQUERY_KEYFILE engine-bigquery-install
207207
$(PIP) install -e ".[bigframes]"
208-
pytest -n auto -m "bigquery" --retries 3 --junitxml=test-results/junit-bigquery.xml
208+
pytest -n auto -m "bigquery" --reruns 3 --junitxml=test-results/junit-bigquery.xml
209209

210210
databricks-test: guard-DATABRICKS_CATALOG guard-DATABRICKS_SERVER_HOSTNAME guard-DATABRICKS_HTTP_PATH guard-DATABRICKS_ACCESS_TOKEN guard-DATABRICKS_CONNECT_VERSION engine-databricks-install
211211
$(PIP) install 'databricks-connect==${DATABRICKS_CONNECT_VERSION}'
212-
pytest -n auto -m "databricks" --retries 3 --junitxml=test-results/junit-databricks.xml
212+
pytest -n auto -m "databricks" --reruns 3 --junitxml=test-results/junit-databricks.xml
213213

214214
redshift-test: guard-REDSHIFT_HOST guard-REDSHIFT_USER guard-REDSHIFT_PASSWORD guard-REDSHIFT_DATABASE engine-redshift-install
215-
pytest -n auto -m "redshift" --retries 3 --junitxml=test-results/junit-redshift.xml
215+
pytest -n auto -m "redshift" --reruns 3 --junitxml=test-results/junit-redshift.xml
216216

217217
clickhouse-cloud-test: guard-CLICKHOUSE_CLOUD_HOST guard-CLICKHOUSE_CLOUD_USERNAME guard-CLICKHOUSE_CLOUD_PASSWORD engine-clickhouse-install
218-
pytest -n 1 -m "clickhouse_cloud" --retries 3 --junitxml=test-results/junit-clickhouse-cloud.xml
218+
pytest -n 1 -m "clickhouse_cloud" --reruns 3 --junitxml=test-results/junit-clickhouse-cloud.xml
219219

220220
athena-test: guard-AWS_ACCESS_KEY_ID guard-AWS_SECRET_ACCESS_KEY guard-ATHENA_S3_WAREHOUSE_LOCATION engine-athena-install
221-
pytest -n auto -m "athena" --retries 3 --junitxml=test-results/junit-athena.xml
221+
pytest -n auto -m "athena" --reruns 3 --junitxml=test-results/junit-athena.xml
222222

223223
fabric-test: guard-FABRIC_HOST guard-FABRIC_CLIENT_ID guard-FABRIC_CLIENT_SECRET guard-FABRIC_DATABASE engine-fabric-install
224-
pytest -n auto -m "fabric" --retries 3 --junitxml=test-results/junit-fabric.xml
224+
pytest -n auto -m "fabric" --reruns 3 --junitxml=test-results/junit-fabric.xml
225225

226226
gcp-postgres-test: guard-GCP_POSTGRES_INSTANCE_CONNECTION_STRING guard-GCP_POSTGRES_USER guard-GCP_POSTGRES_PASSWORD guard-GCP_POSTGRES_KEYFILE_JSON engine-gcppostgres-install
227-
pytest -n auto -m "gcp_postgres" --retries 3 --junitxml=test-results/junit-gcp-postgres.xml
227+
pytest -n auto -m "gcp_postgres" --reruns 3 --junitxml=test-results/junit-gcp-postgres.xml
228228

229229
vscode_settings:
230230
mkdir -p .vscode

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ dev = [
8585
"pytest",
8686
"pytest-asyncio",
8787
"pytest-mock",
88-
"pytest-retry",
88+
"pytest-rerunfailures",
8989
"pytest-xdist",
9090
"pytz",
9191
"redshift_connector",
@@ -280,7 +280,7 @@ log_cli_level = "INFO"
280280
filterwarnings = [
281281
"ignore:The localize method is no longer necessary, as this time zone supports the fold attribute"
282282
]
283-
retry_delay = 10
283+
reruns_delay = 10
284284

285285
[tool.ruff]
286286
line-length = 100

tests/conftest.py

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -212,76 +212,6 @@ def pytest_collection_modifyitems(items, *args, **kwargs):
212212
item.add_marker("fast")
213213

214214

215-
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
216-
def pytest_runtest_makereport(item: pytest.Item, call: pytest.CallInfo):
217-
# The tmp_path fixture frequently throws errors like:
218-
# - KeyError: <_pytest.stash.StashKey object at 0x79ba385fe1a0>
219-
# in its teardown. This causes pytest to mark the test as failed even though we have zero control over this behaviour.
220-
# So we log/swallow that particular error here rather than raising it
221-
222-
# note: the hook always has to yield
223-
outcome = yield
224-
225-
result: pytest.TestReport = outcome.get_result()
226-
227-
if result.when != "teardown":
228-
return result
229-
230-
# If we specifically failed with a StashKey error in teardown, mark the test as passed
231-
if (exception := call.excinfo) and "_pytest.stash.StashKey" in repr(exception):
232-
call.excinfo = None
233-
result.outcome = "passed"
234-
item.add_report_section(
235-
"teardown", "stderr", f"Ignored tmp_path teardown error: {exception}"
236-
)
237-
return result
238-
239-
240-
def pytest_configure(config: pytest.Config):
241-
# we need to adjust the hook order if pytest-retry is present because it:
242-
# - also declares a `pytest_runtest_makereport` with `hookwrapper=True, tryfirst=True`
243-
# - this supersedes our one because pytest always loads plugins first and they take precedence over user code
244-
#
245-
# but, we need our one to run first because it's capturing and ignoring certain errors that cause pytest-retry to fail
246-
# and not retry. so we need to adjust the order the hooks are called which pytest does NOT make easy.
247-
#
248-
# we can't just unload the pytest-retry plugin, load our hook and reload the pytest-retry plugin either.
249-
# this causes an error:
250-
# > Hook 'pytest_set_excluded_exceptions' is already registered within namespace
251-
# because unregister() apparently doesnt unregister plugins cleanly in such a way they can be re-registered
252-
#
253-
# so what we end up doing below is a small monkey-patch to adjust the call order of the hooks
254-
pm = config.pluginmanager
255-
256-
from pluggy._hooks import HookCaller
257-
258-
hook_caller: HookCaller = pm.hook.pytest_runtest_makereport
259-
hook_impls = hook_caller.get_hookimpls()
260-
261-
# find the index of our one
262-
our_makereport_idx = next(
263-
(i for i, v in enumerate(hook_impls) if v.plugin_name.endswith("tests/conftest.py")), None
264-
)
265-
266-
# find the index of the pytest-retry one
267-
pytest_retry_makereport_idx = next(
268-
(i for i, v in enumerate(hook_impls) if v.plugin_name == "pytest-retry"), None
269-
)
270-
271-
if (
272-
pytest_retry_makereport_idx is not None
273-
and our_makereport_idx is not None
274-
and our_makereport_idx > pytest_retry_makereport_idx
275-
):
276-
our_makereport_hook = hook_impls.pop(our_makereport_idx)
277-
278-
# inject our one to run before the pytest-retry one
279-
hook_impls.insert(pytest_retry_makereport_idx, our_makereport_hook)
280-
281-
# HookCaller doesnt have a setter method for this.
282-
hook_caller._hookimpls = hook_impls # type: ignore
283-
284-
285215
# Ignore all local config files
286216
@pytest.fixture(scope="session", autouse=True)
287217
def ignore_local_config_files():

0 commit comments

Comments
 (0)