[tox]
envlist = py{310,py310,311,py311,312,313,313t,314,314t,315,315t}-{brief,full,cover,rest,nocover,niche,custom}
toxworkdir={env:TOX_WORK_DIR:.tox}

[testenv]
basepython={env:TOX_PYTHON_VERSION:python3}
deps =
    -r../requirements/test.txt
extras =
    zoneinfo
allowlist_externals =
    bash
passenv=
    HOME
    LC_ALL
    COVERAGE_FILE
    TOXENV
    # Allow CI builds (or user builds) to force coloured terminal output.
    PY_COLORS
setenv =
    # If PY...ING is set in calling environment, use that; default to 1
    # If PY...ING is set in calling environment, use that; default to 1
    PYTHONWARNDEFAULTENCODING={env:PYTHONWARNDEFAULTENCODING:1}
    brief: HYPOTHESIS_PROFILE=speedy
commands =
    full: bash scripts/basic-test.sh
    brief: python -bb -X dev -m pytest -n auto tests/cover/test_testdecorators.py {posargs}
    cover: python -bb -X dev -m pytest -n auto tests/cover/ tests/pytest/ tests/conjecture/ {posargs}
    rest: python -bb -X dev -m pytest -n auto tests/ --ignore=tests/cover/ --ignore=tests/pytest/ --ignore=tests/conjecture/ --ignore=tests/nocover/ --ignore=tests/quality/ --ignore=tests/ghostwriter/ --ignore=tests/patching/ --ignore=tests/crosshair/test_crosshair.py {posargs}
    conjecture: python -bb -X dev -m pytest -n auto tests/conjecture/ {posargs}
    nocover: python -bb -X dev -m pytest -n auto tests/nocover/ {posargs}
    niche: bash scripts/other-tests.sh
    custom: python -bb -X dev -m pytest {posargs}

[testenv:py310-pyjion]
deps =
    -r../requirements/test.txt
    # We'd like to pin this, but pip-compile has to run under Python 3.10 (+)
    # to do so and that's painful because other tools aren't compatible yet.
    # If it's mid-2022, try again, starting by updating ci_version to 3.10
    pyjion
commands =
    # TODO: restore `-n auto` https://github.com/tonybaloney/Pyjion/issues/456
    # TODO: re-enable in Actions main.yml once this actually works
    pyjion -m pytest tests/cover tests/pytest tests/nocover

[testenv:quality]
deps=
    -r../requirements/test.txt
commands=
    python -bb -X dev -m pytest tests/quality/ -n auto

# This test job runs on the oldest version of CPython we support, against the minimum
# version specified in our runtime dependencies.  For now, that's the oldest version
# with a wheel for non-EOL Python.  In future we might deprecate faster per NEP-29.
[testenv:py310-oldestnumpy]
deps=
    -r../requirements/test.txt
allowlist_externals =
    bash
commands_pre =
    bash -c "pip install --only-binary=:all: numpy==$(grep -m 1 'numpy>=' pyproject.toml | grep -oE '[0-9.]+')"
commands =
    python -bb -X dev -m pytest tests/numpy/ -n auto

# This test job runs against the nightly version of `numpy`
[testenv:numpy-nightly]
deps=
    -r../requirements/test.txt
    pandas
    black
    click
    attrs  # ghostwriter has an attrs test
allowlist_externals =
    bash
commands_pre =
    bash -c "pip install --upgrade --pre --only-binary :all: -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy"
commands =
    python -bb -X dev -m pytest tests/numpy/ tests/array_api/ tests/pandas/ tests/ghostwriter/ tests/conjecture/ tests/cover -n auto {posargs}

# Note: when adding or removing tested Pandas versions, make sure to update the
# docs in numpy.rst too.  To see current download rates of each minor version:
# https://pepy.tech/project/pandas?versions=1.1.*&versions=1.2.*&versions=1.3.*&versions=1.4.*&versions=1.5.*&versions=2.0.*&versions=2.1.*&versions=2.2.*
[testenv:py310-pandas11]
deps =
    -r../requirements/test.txt
    numpy~=1.26.4
    pandas~=1.1.5
commands =
    python -bb -X dev -m pytest tests/pandas -n auto

[testenv:py310-pandas12]
deps =
    -r../requirements/test.txt
    numpy~=1.26.4
    pandas~=1.2.5
commands =
    python -bb -X dev -m pytest tests/pandas -n auto

[testenv:py310-pandas13]
deps =
    -r../requirements/test.txt
    numpy~=1.26.4
    pandas~=1.3.5
commands =
    python -bb -X dev -m pytest tests/pandas -n auto

[testenv:py310-pandas14]
deps =
    -r../requirements/test.txt
    numpy~=1.26.4
    pandas~=1.4.4
commands =
    python -bb -X dev -m pytest tests/pandas -n auto

[testenv:py311-pandas15]
deps =
    -r../requirements/test.txt
    numpy~=1.26.4
    pandas~=1.5.3
commands =
    python -bb -X dev -m pytest tests/pandas -n auto

[testenv:py311-pandas20]
deps =
    -r../requirements/test.txt
    numpy~=1.26.4
    pandas~=2.0.3
commands =
    python -bb -X dev -m pytest tests/pandas -n auto

[testenv:py312-pandas21]
deps =
    -r../requirements/test.txt
    numpy~=1.26.4
    pandas~=2.1.4
setenv=
    PYTHONWARNDEFAULTENCODING=1
commands =
    python -bb -X dev -m pytest tests/pandas -n auto

[testenv:py313-pandas22]
deps =
    -r../requirements/test.txt
    pandas~=2.2.2
    # https://pandas.pydata.org/docs/whatsnew/v2.2.2.html#pandas-2-2-2-is-now-compatible-with-numpy-2-0
setenv=
    PYTHONWARNDEFAULTENCODING=1
commands =
    python -bb -X dev -m pytest tests/pandas -n auto

# Adding a new pandas?  See comment above!

[testenv:rest]
deps =
    -r../requirements/coverage.txt
    -r../requirements/crosshair.txt

[testenv:alt-{rest,nocover}]
deps =
    -r../requirements/test.txt
    -r../requirements/crosshair.txt  # for conformance test
    numpy==1.26.4
    pandas==2.0.3  # latest available as x86 binary wheel
allowlist_externals =
    bash
commands_pre =
    bash -c "grep -v 'numpy=\|pandas=\|pyarrow=' ../requirements/coverage.txt >coverage-mod.txt"
    pip install -r coverage-mod.txt

[testenv:crosshair-{cover,nocover,niche,custom}]
deps =
    -r../requirements/test.txt
    -r../requirements/crosshair.txt
allowlist_externals =
    bash
setenv=
    HYPOTHESIS_PROFILE=crosshair
commands =
    # invoke with `./build.sh check-crosshair-cover -- -x -Wignore`
    cover: python -bb -X dev -m pytest -n auto tests/cover/ tests/pytest/ {posargs}
    nocover: python -bb -X dev -m pytest -n auto tests/nocover/ {posargs}
    niche: bash scripts/other-tests.sh
    custom: python -bb -X dev -m pytest {posargs}

[testenv:django{42,52,60,-nocontrib}]
setenv=
    PYTHONWARNDEFAULTENCODING=1
    DJANGO_SETTINGS_MODULE=tests.django.toys.settings.settings
    nocontrib: DJANGO_SETTINGS_MODULE=tests.django.toys.settings.settings_no_contrib
deps=
    -r../requirements/test.txt
    django42: django==4.2.29
    django52: django==5.2.12
    django60: django==6.0.3
    django-nocontrib: django==6.0.3
commands =
    python -bb -X dev -m tests.django.manage test tests.django {posargs}

[testenv:py{39}-pytest54]
deps =
    -r../requirements/test.txt
commands_pre =
    pip install pytest==5.4.3 pytest-xdist
commands =
    python -bb -X dev -m pytest tests/pytest tests/cover/test_testdecorators.py

[testenv:pytest62]
deps =
    -r../requirements/test.txt
setenv=
    PYTHONWARNDEFAULTENCODING=
commands_pre =
    pip install pytest==6.2.5 pytest-xdist
commands =
    python -bb -X dev -m pytest tests/pytest tests/cover/test_testdecorators.py

[testenv:pytest74]
deps =
    -r../requirements/test.txt
commands_pre =
    pip install pytest==7.4.4 pytest-xdist
commands =
    python -bb -X dev -m pytest tests/pytest tests/cover/test_testdecorators.py

[testenv:pytest84]
deps =
    -r../requirements/test.txt
commands_pre =
    pip install pytest==8.4.2 pytest-xdist
commands =
    python -bb -X dev -m pytest tests/pytest tests/cover/test_testdecorators.py

[testenv:pytest9]
deps =
    -r../requirements/test.txt
commands_pre =
    pip install pytest==9.* pytest-xdist
commands =
    python -bb -X dev -m pytest tests/pytest tests/cover/test_testdecorators.py

[testenv:threading]
deps =
    -r../requirements/test.txt
    # in pytest-run-parallel==0.7.0, python3.10 + pytest-run-parallel + xdist does
    # not collect any tests. I don't know why.
    pytest-run-parallel==0.6.0
setenv=
    PYTHONWARNDEFAULTENCODING=1
    HYPOTHESIS_PROFILE=threading
commands =
    python -bb -X dev -m pytest -n auto tests/cover --parallel-threads 3 --skip-thread-unsafe true {posargs}

[testenv:coverage]
deps =
    -r../requirements/coverage.txt
allowlist_externals =
    rm
setenv=
    PYTHONWARNDEFAULTENCODING=1
    HYPOTHESIS_INTERNAL_COVERAGE=true
    COVERAGE_PROCESS_START=.coveragerc
commands_pre =
    rm -f branch-check*
    pip install .[zoneinfo]
    pip install coverage_enable_subprocess
commands_post =
    pip uninstall -y coverage_enable_subprocess
# Produce a coverage report even if the test suite fails.
# (The tox task will still count as failed.)
ignore_errors = true
# We've had problems correctly measuring coverage using pytest-cov when running
# in parallel, so instead we start coverage implicitly on all (sub-)processes by
# way of the coverage_enable_subprocesses installation. This requires all options
# to be set in .coveragerc (including source), but that's ok as it is overridden
# by --cov=... in conjecture-coverage.
commands =
    python -bb -X dev -m pytest -n auto --ff {posargs} \
        tests/cover tests/conjecture tests/datetime tests/numpy tests/pandas tests/lark \
        tests/redis tests/dpcontracts tests/codemods tests/typing_extensions tests/patching \
        tests/test_annotated_types.py tests/watchdog
    python -m coverage combine
    python -m coverage report
    python scripts/validate_branch_check.py

[testenv:conjecture-coverage]
deps =
    -r../requirements/coverage.txt
setenv=
    PYTHONWARNDEFAULTENCODING=1
    HYPOTHESIS_INTERNAL_COVERAGE=true
commands =
    python -bb -X dev \
        -m pytest -n auto tests/conjecture/ \
        --cov=hypothesis.internal.conjecture --cov-config=.coveragerc {posargs}


[testenv:examples3]
deps=
    -r../requirements/test.txt
commands_pre =
    python -m pip install --editable examples/example_hypothesis_entrypoint
commands =
    python -bb -X dev -m pytest examples
