Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to parallelize unit tests #2139

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ language: python
<<: *reset-prerequisites
- &env-functional
TESTS_TYPE: functional
- &env-unit
TESTS_TYPE: unit
PYTEST_ADDOPTS: >-
'-n auto'
- &env-functional-shard_1
<<: *env-functional
PYTEST_ADDOPTS: >-
Expand All @@ -59,7 +63,7 @@ jobs:
- <<: *py-37
env:
ANSIBLE_VERSION: devel
TESTS_TYPE: unit
<<: *env-unit
- <<: *py-37
env:
<<: *env-functional-shard_1
Expand All @@ -75,7 +79,7 @@ jobs:
- <<: *py-36
env:
ANSIBLE_VERSION: devel
TESTS_TYPE: unit
<<: *env-unit
- <<: *py-36
env:
<<: *env-functional-shard_1
Expand All @@ -91,7 +95,7 @@ jobs:
- <<: *py-27
env:
ANSIBLE_VERSION: devel
TESTS_TYPE: unit
<<: *env-unit
- <<: *py-27
env:
<<: *env-functional-shard_1
Expand Down Expand Up @@ -130,58 +134,58 @@ jobs:
- <<: *py-37
env:
ANSIBLE_VERSION: "28"
TESTS_TYPE: unit
<<: *env-unit
name: unit tests, Ansible 2.8, Python 3.7

- <<: *py-37
env:
ANSIBLE_VERSION: "27"
TESTS_TYPE: unit
<<: *env-unit
name: unit tests, Ansible 2.7, Python 3.7

- <<: *py-37
env:
ANSIBLE_VERSION: "26"
TESTS_TYPE: unit
<<: *env-unit
name: unit tests, Ansible 2.6, Python 3.7

- <<: *py-36
<<: *if-cron-or-manual-run-or-tagged
env:
ANSIBLE_VERSION: "28"
TESTS_TYPE: unit
<<: *env-unit
name: unit tests, Ansible 2.8, Python 3.6

- <<: *py-36
<<: *if-cron-or-manual-run-or-tagged
env:
ANSIBLE_VERSION: "27"
TESTS_TYPE: unit
<<: *env-unit
name: unit tests, Ansible 2.7, Python 3.6

- <<: *py-36
<<: *if-cron-or-manual-run-or-tagged
env:
ANSIBLE_VERSION: "26"
TESTS_TYPE: unit
<<: *env-unit
name: unit tests, Ansible 2.6, Python 3.6

- <<: *py-27
env:
ANSIBLE_VERSION: "28"
TESTS_TYPE: unit
<<: *env-unit
name: unit tests, Ansible 2.8, Python 2.7

- <<: *py-27
env:
ANSIBLE_VERSION: "27"
TESTS_TYPE: unit
<<: *env-unit
name: unit tests, Ansible 2.7, Python 2.7

- <<: *py-27
env:
ANSIBLE_VERSION: "26"
TESTS_TYPE: unit
<<: *env-unit
name: unit tests, Ansible 2.6, Python 2.7

- <<: *py-37
Expand Down Expand Up @@ -362,7 +366,7 @@ jobs:
<<: *if-cron-or-manual-run-or-tagged
env:
ANSIBLE_VERSION: devel
TESTS_TYPE: unit
<<: *env-unit
- <<: *py-37
<<: *if-cron-or-manual-run-or-tagged
env:
Expand All @@ -383,7 +387,7 @@ jobs:
<<: *if-cron-or-manual-run-or-tagged
env:
ANSIBLE_VERSION: devel
TESTS_TYPE: unit
<<: *env-unit
- <<: *py-36
<<: *if-cron-or-manual-run-or-tagged
env:
Expand All @@ -404,7 +408,7 @@ jobs:
<<: *if-cron-or-manual-run-or-tagged
env:
ANSIBLE_VERSION: devel
TESTS_TYPE: unit
<<: *env-unit
- <<: *py-27
<<: *if-cron-or-manual-run-or-tagged
env:
Expand Down
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()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worries me a little bit because potential piling up of remaining file if you break execution. Can't we make the unique code predictable based on test name and python interpreter used, or something similar.

Feel free to ignore my comment if it too hard to fix at this stage, is more of a question, as we can always fix it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, everything is cleaned up. See https://github.com/ansible/molecule/pull/2139/files#diff-93a7df2f35536e469f98fe57544195f7R178. Pytest works like this: yield hands the fixture to the test and then when the test is finished, whatever comes after the yield is the "teardown". So we delete each folder as we make it.

if not os.path.isdir(path):
os.makedirs(path)
yield
shutil.rmtree(str(Path(path).parent))


@pytest.fixture
Expand Down