Skip to content

Commit b9de4ba

Browse files
committed
Silence warnings displayed by python unit tests
There were two categories of warnings being displayed, those related to the xdist plugin, and those related to SQLAlchemy 2.0 migration. The xdist plugin warnings are due to a bug in pytest-cov, see: pytest-dev/pytest-cov#557 We just ignore them entirely for now, as that issue seems to be quiet. The SQLAlchemy 2.0 migration warnings have 2 sub-categories. The first being that `declarative_base` has moved modules, and that warning is removed by using the proper import. However, once that `declarative_base` warning is removed, one encounters: .../pbench/server/database/models/datasets.py:875: RemovedIn20Warning: "Metadata" object is being merged into a Session along the backref cascade path for relationship "Dataset.metadatas"; in SQLAlchemy 2.0, this reverse cascade will not take place. Set cascade_backrefs to False in either the relationship() or backref() function for the 2.0 behavior; or to set globally for the whole Session, set the future=True flag (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9) meta = Metadata(**kwargs) Since we are no going to migrate to SQLAlchemy 2.0 any time soon, it seemed appropriate to just use the big hammer and turn the warnings off entirely.
1 parent 4c6ddf6 commit b9de4ba

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

exec-tests

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ if [[ "${subtst:-python}" == "python" ]]; then
153153

154154
printf -- "\n\n\nRunning %s python3-based unit tests via pytest\n\n" "${major_list// /,}"
155155
_pbench_sources=$(python3 -c 'import inspect, pathlib, pbench; print(pathlib.Path(inspect.getsourcefile(pbench)).parent)')
156-
PYTHONUNBUFFERED=True _PBENCH_COV_DIR="${_toxenvdir}/cov" ${_ECHO} _time pytest \
156+
# We use SQLALCHEMY_SILENCE_UBER_WARNING here to silence very prolific
157+
# warnings posted by SQLAlchemy 1.4.x about features / behaviors being
158+
# used which are not compatible with SQLAlchemy 2.x. Since we are not
159+
# going to switch to 2.x any time soon, we use the big hammer approach
160+
# to avoid the noise.
161+
SQLALCHEMY_SILENCE_UBER_WARNING=1 PYTHONUNBUFFERED=True _PBENCH_COV_DIR="${_toxenvdir}/cov" ${_ECHO} _time pytest \
157162
--tb=native \
158163
${pytest_jobs_arg} \
159164
--basetemp="${_toxenvdir}/tmp" \
@@ -226,7 +231,8 @@ if [[ "${major}" == "all" || "${major}" == "server" ]]; then
226231
server_arg=${1}
227232
shift
228233
posargs="${@}"
229-
PYTHONUNBUFFERED=True PBENCH_SERVER=${server_arg} pytest --tb=native -v -s ${posargs} --pyargs pbench.test.functional.server
234+
# We use SQLALCHEMY_SILENCE_UBER_WARNING here ... (see above).
235+
SQLALCHEMY_SILENCE_UBER_WARNING=1 PYTHONUNBUFFERED=True PBENCH_SERVER=${server_arg} pytest --tb=native -v -s ${posargs} --pyargs pbench.test.functional.server
230236
rc=${?}
231237
fi
232238
fi

lib/pbench/server/database/database.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import sys
22

33
from sqlalchemy import create_engine
4-
from sqlalchemy.ext.declarative import declarative_base
5-
from sqlalchemy.orm import scoped_session, sessionmaker
4+
from sqlalchemy.orm import declarative_base, scoped_session, sessionmaker
65

76
from pbench.server import NoOptionError, NoSectionError
87

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
addopts = -s
33
log_cli=False
44
log_level=DEBUG
5+
filterwarnings=
6+
# Issue #557 in `pytest-cov` (currently v4.x) has not moved for a while now,
7+
# but once a resolution has been adopted we can drop this "ignore".
8+
# Ref: https://github.com/pytest-dev/pytest-cov/issues/557
9+
ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning

0 commit comments

Comments
 (0)