[tox]
isolated_build = true
envlist = {,ci-}py{38,39,310,311,py3},fuzz,run_self

[testenv]
setenv =
    PYTHONPATH = {toxinidir}/src
    PYTHONWARNDEFAULTENCODING = 1
skip_install = True
# We use `recreate=True` because otherwise, on the second run of `tox -e py`,
# the `no_jupyter` tests would run with the jupyter extra dependencies installed.
# See https://github.com/psf/black/issues/2367.
recreate = True
deps =
    -r{toxinidir}/test_requirements.txt
; parallelization is disabled on CI because pytest-dev/pytest-xdist#620 occurs too frequently
; local runs can stay parallelized since they aren't rolling the dice so many times as like on CI
commands =
    pip install -e .[d]
    coverage erase
    pytest tests --run-optional no_jupyter \
        !ci: --numprocesses auto \
        --cov {posargs}
    pip install -e .[jupyter]
    pytest tests --run-optional jupyter \
        -m jupyter \
        !ci: --numprocesses auto \
        --cov --cov-append {posargs}
    coverage report

[testenv:{,ci-}pypy3]
setenv = PYTHONPATH = {toxinidir}/src
skip_install = True
recreate = True
deps =
    -r{toxinidir}/test_requirements.txt
; a separate worker is required in ci due to https://foss.heptapod.net/pypy/pypy/-/issues/3317
; this seems to cause tox to wait forever
; remove this when pypy releases the bugfix
commands =
    pip install -e .[d]
    pytest tests \
        --run-optional no_jupyter \
        !ci: --numprocesses auto \
        ci: --numprocesses 1
    pip install -e .[jupyter]
    pytest tests --run-optional jupyter \
        -m jupyter \
        !ci: --numprocesses auto \
        ci: --numprocesses 1

[testenv:{,ci-}311]
setenv =
  PYTHONPATH = {toxinidir}/src
  AIOHTTP_NO_EXTENSIONS = 1
skip_install = True
recreate = True
deps =
; We currently need > aiohttp 3.8.1 that is on PyPI for 3.11
    git+https://github.com/aio-libs/aiohttp
    -r{toxinidir}/test_requirements.txt
; a separate worker is required in ci due to https://foss.heptapod.net/pypy/pypy/-/issues/3317
; this seems to cause tox to wait forever
; remove this when pypy releases the bugfix
commands =
    pip install -e .[d]
    coverage erase
    pytest tests \
        --run-optional no_jupyter \
        !ci: --numprocesses auto \
        ci: --numprocesses 1 \
        --cov {posargs}
    pip install -e .[jupyter]
    pytest tests --run-optional jupyter \
        -m jupyter \
        !ci: --numprocesses auto \
        ci: --numprocesses 1 \
        --cov --cov-append {posargs}
    coverage report

[testenv:fuzz]
skip_install = True
deps =
    -r{toxinidir}/test_requirements.txt
    hypothesmith
    lark-parser
commands =
    pip install -e .[d]
    coverage erase
    coverage run {toxinidir}/scripts/fuzz.py
    coverage report

[testenv:run_self]
setenv = PYTHONPATH = {toxinidir}/src
skip_install = True
commands =
    pip install -e .[d]
    black --check {toxinidir}/src {toxinidir}/tests
