Tests - parallelize python tests w/ pytest-xdist

This commit is contained in:
Sam
2022-11-19 20:17:58 +01:00
parent df7532a633
commit 872105e2d3
11 changed files with 105 additions and 11 deletions

View File

@ -41,7 +41,11 @@ class TestTestingConfig:
app.config.from_object('fittrackee.config.TestingConfig')
assert app.config['SQLALCHEMY_DATABASE_URI'] == os.environ.get(
'DATABASE_TEST_URL'
'DATABASE_TEST_URL', ''
) + (
f"_{os.getenv('PYTEST_XDIST_WORKER')}"
if os.getenv('PYTEST_XDIST_WORKER')
else ''
)
def test_it_does_not_preserve_context_on_exception(

View File

@ -8,6 +8,7 @@ os.environ['APP_SETTINGS'] = 'fittrackee.config.TestingConfig'
# to avoid resetting dev database during tests
os.environ['DATABASE_URL'] = os.environ['DATABASE_TEST_URL']
TEMP_FOLDER = '/tmp/FitTrackee'
os.makedirs(TEMP_FOLDER, exist_ok=True)
os.environ['UPLOAD_FOLDER'] = TEMP_FOLDER
os.environ['APP_LOG'] = TEMP_FOLDER + '/fittrackee.log'
os.environ['AUTHLIB_INSECURE_TRANSPORT'] = '1'

View File

@ -18,7 +18,11 @@ def get_app_config(
max_users: Optional[int] = None,
) -> Optional[AppConfig]:
if with_config:
config = AppConfig()
config = AppConfig.query.one_or_none()
if not config:
config = AppConfig()
db.session.add(config)
db.session.flush()
config.gpx_limit_import = 10 if max_workouts is None else max_workouts
config.max_single_file_size = (
(1 if max_single_file_size is None else max_single_file_size)
@ -31,7 +35,6 @@ def get_app_config(
* 1024
)
config.max_users = 100 if max_users is None else max_users
db.session.add(config)
db.session.commit()
return config
return None

View File

@ -172,7 +172,7 @@ class TestCreateOAuth2Client:
class TestOAuthCheckScopes:
@pytest.mark.parametrize(
'input_scope', ['', 1, random_string(), [random_string(), 'readwrite']]
'input_scope', ['', 1, 'invalid_scope', ['invalid_scope', 'readwrite']]
)
def test_it_raises_error_when_scope_is_invalid(
self, input_scope: Any
@ -184,11 +184,11 @@ class TestOAuthCheckScopes:
'input_scope,expected_scope',
[
('profile:read', 'profile:read'),
('profile:read ' + random_string(), 'profile:read'),
('profile:read invalid_scope:read', 'profile:read'),
('profile:write', 'profile:write'),
('profile:read profile:write', 'profile:read profile:write'),
(
'profile:write profile:read ' + random_string(),
'profile:write invalid_scope:read profile:read',
'profile:write profile:read',
),
],

View File

@ -1,5 +1,4 @@
from typing import Union
from uuid import uuid4
import pytest
@ -34,7 +33,7 @@ class TestReadableDuration:
('en', '30 seconds'),
('fr', '30 secondes'),
(None, '30 seconds'),
(uuid4().hex, '30 seconds'),
('invalid_locale', '30 seconds'),
],
)
def test_it_returns_duration_in_locale(