mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 22:56:38 +01:00
Run Unit Tests in Parallel (#3283)
This commit is contained in:
parent
24d390e1aa
commit
87b2e29d60
5 changed files with 18 additions and 16 deletions
8
.github/CONTRIBUTING.rst
vendored
8
.github/CONTRIBUTING.rst
vendored
|
@ -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
|
||||
|
|
19
.github/workflows/test.yml
vendored
19
.github/workflows/test.yml
vendored
|
@ -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 ))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 = [
|
||||
|
|
Loading…
Reference in a new issue