Create the app once per run, not once per test

Turns out our tests spent a lot of time recreating the app for each test
case, which is quite intense.

This commit makes the fixture sessions level, so the app is only created
once per test session, not once per test function.

This cuts down the time taken to run the test suite to about 50 seconds.

It also makes the tests more parallelizable. Before this change going
from 4 to 8 processes made the tests slower. Now it cuts them down from
about 50 seconds to about 35 seconds[1]. So this commit also lets Pytest
choose the best number of processes to run, since on my machine it
chooses 8, which is the fastest.

Overall this means the

1. With a 2.2GHz quad-core Intel Core i7 processor on a 2015 MacBook Pro
This commit is contained in:
Chris Hill-Scott
2019-09-17 14:49:42 +01:00
parent e18e2d1e98
commit 1a353d90eb
2 changed files with 2 additions and 4 deletions

View File

@@ -37,5 +37,5 @@ npm test
display_result $? 3 "Front end code style check"
## Code coverage
py.test -n4 --maxfail=10 --cov=app --cov-report=term-missing tests/ --junitxml=test_results.xml --strict -p no:warnings
py.test -n auto --maxfail=10 --cov=app --cov-report=term-missing tests/ --junitxml=test_results.xml --strict -p no:warnings
display_result $? 4 "Code coverage"

View File

@@ -36,7 +36,7 @@ class ElementNotFound(Exception):
pass
@pytest.fixture
@pytest.fixture(scope='session')
def app_(request):
app = Flask('app')
create_app(app)
@@ -47,8 +47,6 @@ def app_(request):
app.test_client_class = TestClient
yield app
ctx.pop()
@pytest.fixture(scope='function')
def service_one(api_user_active):