Fix tests run in random order (#599)
* allow tests to run in random mode * Fix random test mode for fiat-convert * allow random test execution in persistence * fix pep8 styling * use "usefixtures" to prevent pylint "unused parameter" message * add pytest-random-order to travis
This commit is contained in:
parent
248ff3349b
commit
a26cdceb4b
@ -13,7 +13,7 @@ addons:
|
||||
install:
|
||||
- ./install_ta-lib.sh
|
||||
- export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
|
||||
- pip install --upgrade flake8 coveralls
|
||||
- pip install --upgrade flake8 coveralls pytest-random-order
|
||||
- pip install -r requirements.txt
|
||||
- pip install -e .
|
||||
jobs:
|
||||
@ -34,4 +34,4 @@ notifications:
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.cache/pip
|
||||
- ta-lib
|
||||
- ta-lib
|
||||
|
@ -46,7 +46,7 @@ def get_patched_freqtradebot(mocker, config) -> FreqtradeBot:
|
||||
return FreqtradeBot(config, create_engine('sqlite://'))
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@pytest.fixture(scope="function")
|
||||
def default_conf():
|
||||
""" Returns validated configuration suitable for most tests """
|
||||
configuration = {
|
||||
|
@ -16,9 +16,9 @@ from freqtrade.tests.conftest import log_has
|
||||
API_INIT = False
|
||||
|
||||
|
||||
def maybe_init_api(conf, mocker):
|
||||
def maybe_init_api(conf, mocker, force=False):
|
||||
global API_INIT
|
||||
if not API_INIT:
|
||||
if force or not API_INIT:
|
||||
mocker.patch('freqtrade.exchange.validate_pairs',
|
||||
side_effect=lambda s: True)
|
||||
init(config=conf)
|
||||
@ -27,7 +27,7 @@ def maybe_init_api(conf, mocker):
|
||||
|
||||
def test_init(default_conf, mocker, caplog):
|
||||
caplog.set_level(logging.INFO)
|
||||
maybe_init_api(default_conf, mocker)
|
||||
maybe_init_api(default_conf, mocker, True)
|
||||
assert log_has('Instance is running with dry_run enabled', caplog.record_tuples)
|
||||
|
||||
|
||||
|
@ -126,8 +126,10 @@ def test_fiat_convert_get_price(mocker):
|
||||
|
||||
def test_fiat_convert_without_network():
|
||||
# Because CryptoToFiatConverter is a Singleton we reset the value of _coinmarketcap
|
||||
CryptoToFiatConverter._coinmarketcap = None
|
||||
|
||||
fiat_convert = CryptoToFiatConverter()
|
||||
|
||||
CryptoToFiatConverter._coinmarketcap = None
|
||||
|
||||
assert fiat_convert._coinmarketcap is None
|
||||
assert fiat_convert._find_price(crypto_symbol='BTC', fiat_symbol='USD') == 0.0
|
||||
|
@ -8,6 +8,11 @@ from freqtrade.exchange import Exchanges
|
||||
from freqtrade.persistence import Trade, init, clean_dry_run_db
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def init_persistence(default_conf):
|
||||
init(default_conf)
|
||||
|
||||
|
||||
def test_init_create_session(default_conf, mocker):
|
||||
mocker.patch.dict('freqtrade.persistence._CONF', default_conf)
|
||||
|
||||
@ -90,6 +95,7 @@ def test_init_prod_db(default_conf, mocker):
|
||||
os.rename(prod_db_swp, prod_db)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_update_with_bittrex(limit_buy_order, limit_sell_order):
|
||||
"""
|
||||
On this test we will buy and sell a crypto currency.
|
||||
@ -144,6 +150,7 @@ def test_update_with_bittrex(limit_buy_order, limit_sell_order):
|
||||
assert trade.close_date is not None
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_calc_open_close_trade_price(limit_buy_order, limit_sell_order):
|
||||
trade = Trade(
|
||||
pair='BTC_ETH',
|
||||
@ -166,6 +173,7 @@ def test_calc_open_close_trade_price(limit_buy_order, limit_sell_order):
|
||||
assert trade.calc_profit_percent() == 0.06201057
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_calc_close_trade_price_exception(limit_buy_order):
|
||||
trade = Trade(
|
||||
pair='BTC_ETH',
|
||||
@ -179,6 +187,7 @@ def test_calc_close_trade_price_exception(limit_buy_order):
|
||||
assert trade.calc_close_trade_price() == 0.0
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_update_open_order(limit_buy_order):
|
||||
trade = Trade(
|
||||
pair='BTC_ETH',
|
||||
@ -201,6 +210,7 @@ def test_update_open_order(limit_buy_order):
|
||||
assert trade.close_date is None
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_update_invalid_order(limit_buy_order):
|
||||
trade = Trade(
|
||||
pair='BTC_ETH',
|
||||
@ -213,6 +223,7 @@ def test_update_invalid_order(limit_buy_order):
|
||||
trade.update(limit_buy_order)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_calc_open_trade_price(limit_buy_order):
|
||||
trade = Trade(
|
||||
pair='BTC_ETH',
|
||||
@ -230,6 +241,7 @@ def test_calc_open_trade_price(limit_buy_order):
|
||||
assert trade.calc_open_trade_price(fee=0.003) == 0.001003000
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_calc_close_trade_price(limit_buy_order, limit_sell_order):
|
||||
trade = Trade(
|
||||
pair='BTC_ETH',
|
||||
@ -251,6 +263,7 @@ def test_calc_close_trade_price(limit_buy_order, limit_sell_order):
|
||||
assert trade.calc_close_trade_price(fee=0.005) == 0.0010619972
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_calc_profit(limit_buy_order, limit_sell_order):
|
||||
trade = Trade(
|
||||
pair='BTC_ETH',
|
||||
@ -281,6 +294,7 @@ def test_calc_profit(limit_buy_order, limit_sell_order):
|
||||
assert trade.calc_profit(fee=0.003) == 0.00006163
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_calc_profit_percent(limit_buy_order, limit_sell_order):
|
||||
trade = Trade(
|
||||
pair='BTC_ETH',
|
||||
|
Loading…
Reference in New Issue
Block a user