Merge pull request #9590 from freqtrade/enable/xdist

add pytest-xdist to speed up tests
This commit is contained in:
Matthias 2023-12-25 15:57:06 +01:00 committed by GitHub
commit d329ad28c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 5 deletions

View File

@ -44,7 +44,6 @@ jobs:
- name: pip cache (linux) - name: pip cache (linux)
uses: actions/cache@v3 uses: actions/cache@v3
if: runner.os == 'Linux'
with: with:
path: ~/.cache/pip path: ~/.cache/pip
key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip
@ -55,7 +54,6 @@ jobs:
cd build_helpers && ./install_ta-lib.sh ${HOME}/dependencies/; cd .. cd build_helpers && ./install_ta-lib.sh ${HOME}/dependencies/; cd ..
- name: Installation - *nix - name: Installation - *nix
if: runner.os == 'Linux'
run: | run: |
python -m pip install --upgrade pip wheel python -m pip install --upgrade pip wheel
export LD_LIBRARY_PATH=${HOME}/dependencies/lib:$LD_LIBRARY_PATH export LD_LIBRARY_PATH=${HOME}/dependencies/lib:$LD_LIBRARY_PATH
@ -378,7 +376,6 @@ jobs:
- name: pip cache (linux) - name: pip cache (linux)
uses: actions/cache@v3 uses: actions/cache@v3
if: runner.os == 'Linux'
with: with:
path: ~/.cache/pip path: ~/.cache/pip
key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip key: test-${{ matrix.os }}-${{ matrix.python-version }}-pip
@ -389,7 +386,6 @@ jobs:
cd build_helpers && ./install_ta-lib.sh ${HOME}/dependencies/; cd .. cd build_helpers && ./install_ta-lib.sh ${HOME}/dependencies/; cd ..
- name: Installation - *nix - name: Installation - *nix
if: runner.os == 'Linux'
run: | run: |
python -m pip install --upgrade pip wheel python -m pip install --upgrade pip wheel
export LD_LIBRARY_PATH=${HOME}/dependencies/lib:$LD_LIBRARY_PATH export LD_LIBRARY_PATH=${HOME}/dependencies/lib:$LD_LIBRARY_PATH
@ -402,7 +398,7 @@ jobs:
env: env:
CI_WEB_PROXY: http://152.67.78.211:13128 CI_WEB_PROXY: http://152.67.78.211:13128
run: | run: |
pytest --random-order --cov=freqtrade --cov-config=.coveragerc --longrun pytest --random-order --longrun --durations 20 -n auto --dist loadscope
# Notify only once - when CI completes (and after deploy) in case it's successfull # Notify only once - when CI completes (and after deploy) in case it's successfull

View File

@ -15,6 +15,7 @@ pytest-asyncio==0.21.1
pytest-cov==4.1.0 pytest-cov==4.1.0
pytest-mock==3.12.0 pytest-mock==3.12.0
pytest-random-order==1.1.0 pytest-random-order==1.1.0
pytest-xdist==3.5.0
isort==5.13.2 isort==5.13.2
# For datetime mocking # For datetime mocking
time-machine==2.13.0 time-machine==2.13.0

View File

@ -11,6 +11,7 @@ from unittest.mock import MagicMock, Mock, PropertyMock
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import pytest import pytest
from xdist.scheduler.loadscope import LoadScopeScheduling
from freqtrade import constants from freqtrade import constants
from freqtrade.commands import Arguments from freqtrade.commands import Arguments
@ -56,6 +57,27 @@ def pytest_configure(config):
setattr(config.option, 'markexpr', 'not longrun') setattr(config.option, 'markexpr', 'not longrun')
class FixtureScheduler(LoadScopeScheduling):
# Based on the suggestion in
# https://github.com/pytest-dev/pytest-xdist/issues/18
def _split_scope(self, nodeid):
if 'exchange_online' in nodeid:
try:
# Extract exchange ID from nodeid
exchange_id = nodeid.split('[')[1].split('-')[0].rstrip(']')
return exchange_id
except Exception as e:
print(e)
pass
return nodeid
def pytest_xdist_make_scheduler(config, log):
return FixtureScheduler(config, log)
def log_has(line, logs): def log_has(line, logs):
"""Check if line is found on some caplog's message.""" """Check if line is found on some caplog's message."""
return any(line == message for message in logs.messages) return any(line == message for message in logs.messages)