Skip to content

Commit

Permalink
Parallelize unit test execution (ansible#2140)
Browse files Browse the repository at this point in the history
Enables parallel mode when calling unittests. User is still able to
disable this behavior by defining his own PYTEST_ADDOPTS value.

Signed-off-by: Sorin Sbarnea <[email protected]>
Co-Authored-by: Luke Murphy <[email protected]>
  • Loading branch information
ssbarnea and decentral1se committed Jul 2, 2019
1 parent ddc8b6a commit eb6666c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 4 additions & 3 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ def get_molecule_file(path):


@pytest.helpers.register
def molecule_ephemeral_directory():
project_directory = 'test-project'
def molecule_ephemeral_directory(_fixture_uuid):
project_directory = 'test-project-{}'.format(_fixture_uuid)
scenario_name = 'test-instance'

return ephemeral_directory(os.path.join(project_directory, scenario_name))
return ephemeral_directory(
os.path.join('molecule_test', project_directory, scenario_name))


def pytest_addoption(parser):
Expand Down
9 changes: 8 additions & 1 deletion test/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from uuid import uuid4
import copy
import functools
import glob
import os
import re
import shutil
try:
from pathlib import Path
except ImportError:
from pathlib2 import Path

import pytest

Expand Down Expand Up @@ -167,9 +172,11 @@ def molecule_scenario_directory_fixture(molecule_directory_fixture):

@pytest.fixture
def molecule_ephemeral_directory_fixture(molecule_scenario_directory_fixture):
path = pytest.helpers.molecule_ephemeral_directory()
path = pytest.helpers.molecule_ephemeral_directory(str(uuid4()))
if not os.path.isdir(path):
os.makedirs(path)
yield
shutil.rmtree(str(Path(path).parent))


@pytest.fixture
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ passenv = *
setenv =
ANSIBLE_CALLABLE_WHITELIST={env:ANSIBLE_CALLABLE_WHITELIST:timer,profile_roles}
PYTHONDONTWRITEBYTECODE=1
unit: PYTEST_ADDOPTS=test/unit/ --cov={toxinidir}/molecule/ --no-cov-on-fail {env:PYTEST_ADDOPTS:}
# -n auto used only on unit as is not supported by functional yet
unit: PYTEST_ADDOPTS=test/unit/ --cov={toxinidir}/molecule/ --no-cov-on-fail {env:PYTEST_ADDOPTS:-n auto}
functional: PYTEST_ADDOPTS=test/functional/ {env:PYTEST_ADDOPTS:}
deps =
flake8>=3.6.0,<4
Expand Down

0 comments on commit eb6666c

Please sign in to comment.