From d89d523fbb35909966dd1da3a74749b3e6b38d24 Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Tue, 4 Jan 2022 13:19:32 -0500 Subject: [PATCH] chore: handle more warnings in test suite (#10547) * chore: replace deprecated scalar method SQLAlchemy 1.4.x deprecated the `.as_scalar()` method and replaced it with `.scalar_subquery()` and issued a `SADeprecationWarning`. Refs: https://docs.sqlalchemy.org/en/14/changelog/changelog_14.html#change-f413ff8c13a1fb7d766bfa16dfcdfbf1 Signed-off-by: Mike Fiedler * test: ignore InsecureStorageWarning When another class was added, it wasn't excluded from the warnings report. Refs: #9792 Original ignore: #4360 Signed-off-by: Mike Fiedler * test: ignore CIText warnings in test output The updated SQLAlchemy library now emits 2,000+ warnings for CIText(). I've opened an issue on the responsible repo. Refs: https://github.com/mahmoudimus/sqlalchemy-citext/issues/25 Signed-off-by: Mike Fiedler * test: filter out known legacy behavior in test The test case knowingly creates invalid versions, and the code handles them by performing some extra validation, and throws the error. Suppress the warnings for creating `LegacyVersion`. Signed-off-by: Mike Fiedler * test: filter out SAWarning for invalidation The collections used in the test case are intentionally being modified. Signed-off-by: Mike Fiedler Co-authored-by: Dustin Ingram --- pyproject.toml | 2 ++ tests/unit/forklift/test_legacy.py | 2 ++ tests/unit/packaging/test_tasks.py | 3 +++ warehouse/accounts/models.py | 2 +- warehouse/search/tasks.py | 4 ++-- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 15a9bdd9eb2d..941c45ae949b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,5 +15,7 @@ markers = [ 'functional: Slower running tests which test the entire system is functioning.', ] filterwarnings = [ + 'ignore::warehouse.admin.services.InsecureStorageWarning', 'ignore::warehouse.packaging.services.InsecureStorageWarning', + 'ignore:UserDefinedType CIText.*:sqlalchemy.exc.SAWarning' # See https://github.com/mahmoudimus/sqlalchemy-citext/issues/25 ] diff --git a/tests/unit/forklift/test_legacy.py b/tests/unit/forklift/test_legacy.py index 4471f5adb497..3118f20b64ed 100644 --- a/tests/unit/forklift/test_legacy.py +++ b/tests/unit/forklift/test_legacy.py @@ -104,6 +104,7 @@ def test_validates_valid_pep440_version(self, version): form, field = pretend.stub(), pretend.stub(data=version) legacy._validate_pep440_version(form, field) + @pytest.mark.filterwarnings("ignore:Creating a LegacyVersion.*:DeprecationWarning") @pytest.mark.parametrize("version", ["dog", "1.0.dev.a1", "1.0+local"]) def test_validates_invalid_pep440_version(self, version): form, field = pretend.stub(), pretend.stub(data=version) @@ -992,6 +993,7 @@ def test_fails_invalid_version(self, pyramid_config, pyramid_request, version): ), ], ) + @pytest.mark.filterwarnings("ignore:Creating a LegacyVersion.*:DeprecationWarning") def test_fails_invalid_post_data( self, pyramid_config, db_request, post_data, message ): diff --git a/tests/unit/packaging/test_tasks.py b/tests/unit/packaging/test_tasks.py index e9b371876087..44b73ce62deb 100644 --- a/tests/unit/packaging/test_tasks.py +++ b/tests/unit/packaging/test_tasks.py @@ -404,6 +404,9 @@ def find_service(name=None): class TestSyncBigQueryMetadata: + @pytest.mark.filterwarnings( + "ignore:This collection has been invalidated.:sqlalchemy.exc.SAWarning" + ) @pytest.mark.parametrize( ("release_files_table", "expected_get_table_calls"), [ diff --git a/warehouse/accounts/models.py b/warehouse/accounts/models.py index 036273f3b868..1984ce056105 100644 --- a/warehouse/accounts/models.py +++ b/warehouse/accounts/models.py @@ -140,7 +140,7 @@ def email(self): return ( select([Email.email]) .where((Email.user_id == self.id) & (Email.primary.is_(True))) - .as_scalar() + .scalar_subquery() ) @property diff --git a/warehouse/search/tasks.py b/warehouse/search/tasks.py index 0762dc7081d2..8e6632091ed0 100644 --- a/warehouse/search/tasks.py +++ b/warehouse/search/tasks.py @@ -61,7 +61,7 @@ def _project_docs(db, project_name=None): db.query(func.array_agg(r.version)) .filter(r.project_id == Release.project_id) .correlate(Release) - .as_scalar() + .scalar_subquery() .label("all_versions") ) @@ -71,7 +71,7 @@ def _project_docs(db, project_name=None): .join(Classifier, Classifier.id == release_classifiers.c.trove_id) .filter(Release.id == release_classifiers.c.release_id) .correlate(Release) - .as_scalar() + .scalar_subquery() .label("classifiers") )