
[tox]
envlist = py

[testenv]
# note that we have a .coveragerc file that points coverage specifically
# at ./lib/sqlalchemy, and *not* at the build that tox might create under .tox.
# See the notes below for setenv for more detail.
# also using --cov-append so that we can aggregate multiple runs together.
# Jenkins etc. need to call "coverage erase" externally.
cov_args=--cov=sqlalchemy --cov-report term --cov-append --cov-report xml --exclude-tag memory-intensive --exclude-tag timing-intensive -k "not aaa_profiling"

install_command=python -m pip install {env:TOX_PIP_OPTS:} {opts} {packages}

usedevelop=
     cov: True

deps=pytest>=4.6.11 # this can be 6.x once we are on python 3 only
     pytest-xdist
     greenlet
     mock; python_version < '3.3'
     importlib_metadata; python_version < '3.8'
     postgresql: .[postgresql]
     postgresql: .[postgresql_asyncpg]; python_version >= '3'
     postgresql: .[postgresql_pg8000]; python_version >= '3'
     mysql: .[mysql]
     mysql: .[pymysql]
     mysql: .[mariadb_connector]; python_version >= '3'

     # we should probably try to get mysql_connector back in the mix
     # as well
     # mysql: .[mysql_connector]; python_version >= '3'

     oracle: .[oracle]
     mssql: .[mssql]

     cov: pytest-cov

whitelist_externals=sh

# PYTHONPATH - erased so that we use the build that's present
# in .tox as the SQLAlchemy library to be imported
#
# PYTHONUSERSITE - this *MUST* be set so that the ./lib/ import
# set up explicitly in test/conftest.py is *disabled*, again so that
# when SQLAlchemy is built into the .tox area, we use that and not the
# local checkout, at least when usedevelop=False
#
# BASECOMMAND - using an env variable here so we can use it
# as a substitution in a command (see https://bitbucket.org/hpk42/tox/issues/307/)
#
# only use --dropfirst option if we're *not* using -n;
# if -n is used, we're working in brand new DBs anyway, dropfirst
# will collide on CI environments
setenv=
    PYTHONPATH=
    PYTHONNOUSERSITE=1
    MEMUSAGE=--nomemory
    SQLALCHEMY_WARN_20=true
    BASECOMMAND=python -m pytest --rootdir {toxinidir} --log-info=sqlalchemy.testing

    WORKERS={env:TOX_WORKERS:-n4  --max-worker-restart=5}

    nocext: DISABLE_SQLALCHEMY_CEXT=1
    cext: REQUIRE_SQLALCHEMY_CEXT=1
    cov: COVERAGE={[testenv]cov_args}
    backendonly: BACKENDONLY=--backend-only
    memusage: MEMUSAGE='-k test_memusage'

    oracle: WORKERS={env:TOX_WORKERS:-n2  --max-worker-restart=5}
    oracle: ORACLE={env:TOX_ORACLE:--db oracle}

    sqlite: SQLITE={env:TOX_SQLITE:--db sqlite}
    sqlite_file: SQLITE={env:TOX_SQLITE_FILE:--db sqlite_file}

    postgresql: POSTGRESQL={env:TOX_POSTGRESQL:--db postgresql}
    py3{,5,6,7,8,9,10,11}-postgresql: EXTRA_PG_DRIVERS={env:EXTRA_PG_DRIVERS:--dbdriver psycopg2 --dbdriver asyncpg?async_fallback=true --dbdriver pg8000}

    mysql: MYSQL={env:TOX_MYSQL:--db mysql}
    mysql: EXTRA_MYSQL_DRIVERS={env:EXTRA_MYSQL_DRIVERS:--dbdriver mysqldb --dbdriver pymysql}
    py3{,5,6,7,8,9,10,11}-mysql: EXTRA_MYSQL_DRIVERS={env:EXTRA_MYSQL_DRIVERS:--dbdriver mysqldb --dbdriver pymysql --dbdriver mariadbconnector}


    mssql: MSSQL={env:TOX_MSSQL:--db mssql}

    oracle,mssql,sqlite_file: IDENTS=--write-idents db_idents.txt
    oracle,mssql,sqlite_file: MEMUSAGE=--nomemory

# tox as of 2.0 blocks all environment variables from the
# outside, unless they are here (or in TOX_TESTENV_PASSENV,
# wildcards OK).  Need at least these
passenv=ORACLE_HOME NLS_LANG TOX_POSTGRESQL TOX_MYSQL TOX_ORACLE TOX_MSSQL TOX_SQLITE TOX_SQLITE_FILE TOX_WORKERS EXTRA_PG_DRIVERS EXTRA_MYSQL_DRIVERS

# for nocext, we rm *.so in lib in case we are doing usedevelop=True
commands=
  cext: /bin/true
  nocext: sh -c "rm -f lib/sqlalchemy/*.so"
  {env:BASECOMMAND} {env:WORKERS} {env:SQLITE:} {env:POSTGRESQL:} {env:EXTRA_PG_DRIVERS:} {env:MYSQL:} {env:EXTRA_MYSQL_DRIVERS:} {env:ORACLE:} {env:MSSQL:} {env:BACKENDONLY:} {env:IDENTS:} {env:MEMUSAGE:} {env:COVERAGE:} {posargs}
  oracle,mssql,sqlite_file: python reap_dbs.py db_idents.txt

# thanks to https://julien.danjou.info/the-best-flake8-extensions/
[testenv:pep8]
basepython = python3.7
deps=
      flake8
      flake8-import-order
      flake8-builtins
      flake8-docstrings>=1.3.1
      flake8-rst-docstrings
      # flake8-rst-docstrings depdendency, leaving it here
      # in case it requires a version pin
      pydocstyle
      pygments
      black==20.8b1
commands =
     flake8 ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py {posargs}
     black --check .

# command run in the github action when cext are active.
[testenv:github-cext]
commands=
  python -m pytest {env:WORKERS} {env:SQLITE:} {env:POSTGRESQL:} {env:MYSQL:} {env:ORACLE:} {env:MSSQL:} {env:BACKENDONLY:} {env:IDENTS:} {env:MEMUSAGE:} {env:COVERAGE:} {posargs}
  oracle,mssql,sqlite_file: python reap_dbs.py db_idents.txt

# command run in the github action when cext are not active.
[testenv:github-nocext]
commands=
  python -m pytest {env:WORKERS} {env:SQLITE:} {env:POSTGRESQL:} {env:MYSQL:} {env:ORACLE:} {env:MSSQL:} {env:BACKENDONLY:} {env:IDENTS:} {env:MEMUSAGE:} {env:COVERAGE:} {posargs}
  oracle,mssql,sqlite_file: python reap_dbs.py db_idents.txt
