Skip to content

Comments

Respect @pytest.mark.filterwarnings in prohibited warnings#38684

Merged
Taragolis merged 2 commits intoapache:mainfrom
Taragolis:add-warnings-as-filter-warnings
Apr 4, 2024
Merged

Respect @pytest.mark.filterwarnings in prohibited warnings#38684
Taragolis merged 2 commits intoapache:mainfrom
Taragolis:add-warnings-as-filter-warnings

Conversation

@Taragolis
Copy link
Contributor

Found this issue when tried to resolve some warnings in tests, in current implementation we add error filter before start the test but when @pytest.mark.filterwarnings already add filter into the warning.filters in this case this code still raise an error

@pytest.mark.filterwarnings("ignore::airflow.exceptions.RemovedInAirflow3Warning")
def test_suite():
    warnings.warn("Surprise Surprise", category=RemovedInAirflow3Warning)

The solution pretty simple add appropriate markers during the tests collection, when test item just collected, and add it before all explicitly set markers. in this case the order of marker execution would be same as this code

@pytest.mark.filterwarnings("ignore::airflow.exceptions.RemovedInAirflow3Warning")
@pytest.mark.filterwarnings("error::airflow.exceptions.RemovedInAirflow3Warning")
@pytest.mark.filterwarnings("error::airflow.utils.context.AirflowContextDeprecationWarning")
@pytest.mark.filterwarnings("error::airflow.exceptions.AirflowProviderDeprecationWarning")
def test_suite():
    warnings.warn("Surprise Surprise", category=RemovedInAirflow3Warning)

which turned into the this order into the warning.filters

00 = {tuple: 5} ('ignore', None, <class 'airflow.exceptions.RemovedInAirflow3Warning'>, None, 0)
01 = {tuple: 5} ('error', None, <class 'airflow.exceptions.RemovedInAirflow3Warning'>, None, 0)
02 = {tuple: 5} ('error', None, <class 'airflow.utils.context.AirflowContextDeprecationWarning'>, None, 0)
03 = {tuple: 5} ('error', None, <class 'airflow.exceptions.AirflowProviderDeprecationWarning'>, None, 0)
...

I've check this behaviour in both pytest 7.4 and pytest 8.1+


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@Taragolis Taragolis added full tests needed We need to run full set of tests for this PR to merge all versions If set, the CI build will be forced to use all versions of Python/K8S/DBs labels Apr 2, 2024
@Taragolis Taragolis requested review from potiuk and uranusjr April 2, 2024 16:55
@Taragolis Taragolis added the changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) label Apr 2, 2024
@Taragolis
Copy link
Contributor Author

An unpleasant side effect: now it also affects warnings in fixtures, e.g. DagBag which collect example DAGs skip all DAGs which contain deprecated stuff, e.g. SubDagOperator. Need to find better way to import it, for now import it with temporary suppress warnings.

@Taragolis
Copy link
Contributor Author

One more rebase before merge

@Taragolis Taragolis force-pushed the add-warnings-as-filter-warnings branch from 95c9c85 to 6b1c3fc Compare April 4, 2024 10:40
@Taragolis Taragolis merged commit b606b96 into apache:main Apr 4, 2024
@Taragolis Taragolis deleted the add-warnings-as-filter-warnings branch April 4, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

all versions If set, the CI build will be forced to use all versions of Python/K8S/DBs changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) full tests needed We need to run full set of tests for this PR to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants