diff --git a/.github/CONTRIBUTING.rst b/.github/CONTRIBUTING.rst index 3e7dc6d12..040a37277 100644 --- a/.github/CONTRIBUTING.rst +++ b/.github/CONTRIBUTING.rst @@ -98,6 +98,13 @@ Here's how to make a one-off code change. $ pytest -v + Since the tests can take a while to run, you can speed things up by running them in parallel + using `pytest-xdist`_ (note that this may effect the result of the test in some rare cases): + + .. code-block:: bash + + $ pytest -v -n auto --dist=loadfile + To run ``test_official`` (particularly useful if you made API changes), run .. code-block:: bash @@ -280,3 +287,4 @@ break the API classes. For example: .. _`RTD build`: https://docs.python-telegram-bot.org/en/doc-fixes .. _`CSI`: https://standards.mousepawmedia.com/en/stable/csi.html .. _`section`: #documenting +.. _`pytest-xdist`: https://github.com/pytest-dev/pytest-xdist diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d7f5b7b84..7c73e11d8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,22 +14,10 @@ jobs: pytest: name: pytest runs-on: ${{matrix.os}} - continue-on-error: ${{ matrix.experimental }} strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11.0-rc.2'] os: [ubuntu-latest, windows-latest, macos-latest] - experimental: [false] - include: - - python-version: 3.11.0-rc.2 - os: ubuntu-latest - experimental: true - - python-version: 3.11.0-rc.2 - os: windows-latest - experimental: true - - python-version: 3.11.0-rc.2 - os: macos-latest - experimental: true fail-fast: False steps: - uses: actions/checkout@v3 @@ -44,6 +32,7 @@ jobs: python -W ignore -m pip install -r requirements.txt python -W ignore -m pip install -r requirements-opts.txt python -W ignore -m pip install -r requirements-dev.txt + python -W ignore -m pip install pytest-xdist[psutil] - name: Test with pytest # We run 4 different suites here @@ -65,7 +54,9 @@ jobs: no_rate_limiter_exit=$? export TEST_RATE_LIMITER='true' pip install -r requirements-opts.txt - pytest -v --cov --cov-append + # `-n auto --dist loadfile` uses pytest-xdist to run each test file on a different CPU + # worker + pytest -v --cov --cov-append -n auto --dist loadfile full_exit=$? special_exit=$(( no_pytz_exit > no_passport_exit ? no_pytz_exit : no_passport_exit )) special_exit=$(( special_exit > no_rate_limiter_exit ? special_exit : no_rate_limiter_exit )) diff --git a/requirements-dev.txt b/requirements-dev.txt index f6701c2ef..ba96e65a9 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,6 +3,7 @@ pre-commit pytest==7.1.3 pytest-asyncio==0.19.0 pytest-timeout==2.1.0 # used to timeout tests +pytest-xdist==2.5.0 # xdist runs tests in parallel flaky # Used for flaky tests (flaky decorator) beautifulsoup4 # used in test_official for parsing tg docs diff --git a/tests/test_bot.py b/tests/test_bot.py index 8e94e1cb1..209139237 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -279,6 +279,8 @@ class TestBot: print(record) if record.getMessage().startswith("Task was destroyed but it is pending"): caplog.records.pop(idx) + if record.getMessage().startswith("Task exception was never retrieved"): + caplog.records.pop(idx) assert len(caplog.records) == 3 assert caplog.records[0].getMessage().startswith("Entering: get_me") assert caplog.records[-1].getMessage().startswith("Exiting: get_me") diff --git a/tests/test_datetime.py b/tests/test_datetime.py index 38a820102..013053703 100644 --- a/tests/test_datetime.py +++ b/tests/test_datetime.py @@ -31,8 +31,8 @@ from telegram.ext import Defaults from tests.conftest import env_var_2_bool ABSOLUTE_TIME_SPECS = [ - dtm.datetime.now(tz=dtm.timezone(dtm.timedelta(hours=-7))), - dtm.datetime.utcnow(), + dtm.datetime.now(tz=dtm.timezone(dtm.timedelta(hours=-7))).replace(second=0, microsecond=0), + dtm.datetime.utcnow().replace(second=0, microsecond=0), ] DELTA_TIME_SPECS = [dtm.timedelta(hours=3, seconds=42, milliseconds=2), 30, 7.5] TIME_OF_DAY_TIME_SPECS = [