language: python
dist: xenial
python: '3.7.4'
cache: false

env:
  global:
    - PYTEST_ADDOPTS="-vv --showlocals --durations=100 --exitfirst"
    - PYTEST_COVERAGE=1

# setuptools-scm needs all tags in order to obtain a proper version
git:
  depth: false

install:
  - python -m pip install --upgrade --pre tox

jobs:
  include:
    # Coverage for:
    # - TestArgComplete (linux only)
    # - numpy
    # - verbose=0
    - stage: baseline
      env: TOXENV=py27-xdist
      python: '2.7'

    - env: TOXENV=py38-xdist
      python: '3.8'

    - stage: tests
    # - _pytest.unittest._handle_skip (via pexpect).
      env: TOXENV=py27-pexpect,py27-twisted
      python: '2.7'

    - env: TOXENV=py35-xdist
      python: '3.5.9'

    - env: TOXENV=py36-xdist PYTEST_REORDER_TESTS=0
      python: '3.6.9'

    - env: TOXENV=py37-numpy-pexpect-twisted
      python: '3.7.4'

    # - test_sys_breakpoint_interception (via pexpect).
    - env: TOXENV=py37-pexpect,py37-twisted
      python: '3.7.4'

    # Run also non-verbosely, to gain coverage
    - env: TOXENV=py38-xdist PYTEST_ADDOPTS=""
      python: '3.8'

    - env: TOXENV=linting,docs,doctesting
      cache:
        directories:
          - $HOME/.cache/pre-commit

before_script:
  - |
    # Do not (re-)upload coverage with cron runs.
    if [[ "$TRAVIS_EVENT_TYPE" = cron ]]; then
      PYTEST_COVERAGE=0
    fi
  - |
    if [[ "$PYTEST_COVERAGE" = 1 ]]; then
      export COVERAGE_FILE="$PWD/.coverage"
      export COVERAGE_PROCESS_START="$PWD/.coveragerc"
      export _PYTEST_TOX_COVERAGE_RUN="coverage run -m"
      export _PYTEST_TOX_EXTRA_DEP=coverage-enable-subprocess
    fi
script: env COLUMNS=120 python -m tox

after_success:
  - |
    if [[ "$PYTEST_COVERAGE" = 1 ]]; then
      env CODECOV_NAME="$TOXENV-$TRAVIS_OS_NAME" scripts/report-coverage.sh
    fi
branches:
  only:
    - 4.6.x
