Skip to content

Commit

Permalink
Silence warnings display by python unit tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
portante committed Jan 12, 2023
1 parent 7c95c86 commit 0400233
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions exec-tests
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ if [[ "${subtst:-python}" == "python" ]]; then

printf -- "\n\n\nRunning %s python3-based unit tests via pytest\n\n" "${major_list// /,}"
_pbench_sources=$(python3 -c 'import inspect, pathlib, pbench; print(pathlib.Path(inspect.getsourcefile(pbench)).parent)')
PYTHONUNBUFFERED=True _PBENCH_COV_DIR="${_toxenvdir}/cov" ${_ECHO} _time pytest \
SQLALCHEMY_SILENCE_UBER_WARNING=1 PYTHONUNBUFFERED=True _PBENCH_COV_DIR="${_toxenvdir}/cov" ${_ECHO} _time pytest \
--tb=native \
${pytest_jobs_arg} \
--basetemp="${_toxenvdir}/tmp" \
Expand Down Expand Up @@ -226,7 +226,7 @@ if [[ "${major}" == "all" || "${major}" == "server" ]]; then
server_arg=${1}
shift
posargs="${@}"
PYTHONUNBUFFERED=True PBENCH_SERVER=${server_arg} pytest --tb=native -v -s ${posargs} --pyargs pbench.test.functional.server
SQLALCHEMY_SILENCE_UBER_WARNING=1 PYTHONUNBUFFERED=True PBENCH_SERVER=${server_arg} pytest --tb=native -v -s ${posargs} --pyargs pbench.test.functional.server
rc=${?}
fi
fi
Expand Down
3 changes: 1 addition & 2 deletions lib/pbench/server/database/database.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import sys

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.orm import declarative_base, scoped_session, sessionmaker

from pbench.server import NoOptionError, NoSectionError

Expand Down
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
addopts = -s
log_cli=False
log_level=DEBUG
filterwarnings=
# FIXME: drop this once `pytest-cov` is updated.
# Ref: https://github.com/pytest-dev/pytest-cov/issues/557
ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning

0 comments on commit 0400233

Please sign in to comment.