Skip to content

Commit

Permalink
Remove dependency to molecule.test (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianonicolai authored Nov 16, 2023
1 parent c3068ab commit 196ed1e
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 18 deletions.
22 changes: 22 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextlib
import os
import random
import shutil
import string

import pytest
Expand Down Expand Up @@ -84,3 +85,24 @@ def molecule_ephemeral_directory(_fixture_uuid):
return ephemeral_directory(
os.path.join("molecule_test", project_directory, scenario_name),
)


def metadata_lint_update(role_directory: str) -> None:
# By default, ansible-lint will fail on newly-created roles because the
# fields in this file have not been changed from their defaults. This is
# good because molecule should create this file using the defaults, and
# users should receive feedback to change these defaults. However, this
# blocks the testing of 'molecule init' itself, so ansible-lint should
# be configured to ignore these metadata lint errors.
dirname = os.path.dirname(os.path.abspath(__file__))
ansible_lint_src = os.path.join(dirname, ".ansible-lint")
shutil.copy(ansible_lint_src, role_directory)

# Explicitly lint here to catch any unexpected lint errors before
# continuining functional testing. Ansible lint is run at the root
# of the role directory and pointed at the role directory to ensure
# the customize ansible-lint config is used.
with change_dir_to(role_directory):
cmd = ["ansible-lint", "."]
result = run_command(cmd)
assert result.returncode == 0
2 changes: 1 addition & 1 deletion test/azure/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
# DEALINGS IN THE SOFTWARE.


from molecule.test.conftest import * # noqa
from conftest import * # noqa
2 changes: 1 addition & 1 deletion test/azure/functional/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

import pytest

from conftest import change_dir_to
from molecule import logger
from molecule.test.conftest import change_dir_to
from molecule.util import run_command

LOG = logger.get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion test/containers/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
# DEALINGS IN THE SOFTWARE.
"""PyTest Config."""

from molecule.test.conftest import * # noqa pylint: disable=wildcard-import,unused-wildcard-import
from conftest import * # noqa pylint: disable=wildcard-import,unused-wildcard-import
2 changes: 1 addition & 1 deletion test/containers/functional/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"""Functional Tests."""
import os

from conftest import change_dir_to, molecule_directory
from molecule import logger
from molecule.test.conftest import change_dir_to, molecule_directory
from molecule.util import run_command

LOG = logger.get_logger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions test/docker/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Pytest Fixtures."""
import pytest
from conftest import random_string, temp_dir # noqa

from molecule.test.conftest import random_string, temp_dir # noqa
import pytest


@pytest.fixture()
Expand Down
2 changes: 1 addition & 1 deletion test/docker/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import pytest

from conftest import change_dir_to
from molecule import logger
from molecule.test.conftest import change_dir_to
from molecule.util import run_command

LOG = logger.get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion test/ec2/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
# DEALINGS IN THE SOFTWARE.


from molecule.test.conftest import * # noqa
from conftest import * # noqa
3 changes: 1 addition & 2 deletions test/ec2/functional/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@

import pytest

from conftest import change_dir_to, metadata_lint_update
from molecule import logger
from molecule.test.b_functional.conftest import metadata_lint_update
from molecule.test.conftest import change_dir_to
from molecule.util import run_command

LOG = logger.get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion test/gce/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
# DEALINGS IN THE SOFTWARE.


from molecule.test.conftest import * # noqa
from conftest import * # noqa
3 changes: 1 addition & 2 deletions test/gce/functional/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@

import pytest

from conftest import change_dir_to, metadata_lint_update
from molecule import logger
from molecule.test.b_functional.conftest import metadata_lint_update
from molecule.test.conftest import change_dir_to
from molecule.util import run_command

LOG = logger.get_logger(__name__)
Expand Down
3 changes: 1 addition & 2 deletions test/gce/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@


def test_gce_driver_is_detected():
driver_name = __name__.split(".")[0].split("_")[-1]
drivers = [str(d) for d in api.drivers()]
assert driver_name in drivers
assert "gce" in drivers
2 changes: 1 addition & 1 deletion test/podman/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pathlib
import subprocess

from conftest import change_dir_to
from molecule import logger
from molecule.test.conftest import change_dir_to
from molecule.util import run_command
from molecule_plugins.podman import __file__ as module_file

Expand Down
2 changes: 1 addition & 1 deletion test/vagrant/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
# DEALINGS IN THE SOFTWARE.


from molecule.test.conftest import * # noqa
from conftest import * # noqa
2 changes: 1 addition & 1 deletion test/vagrant/functional/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import pytest

import vagrant
from conftest import change_dir_to
from molecule import logger, util
from molecule.scenario import ephemeral_directory
from molecule.test.conftest import change_dir_to
from molecule.util import run_command

LOG = logger.get_logger(__name__)
Expand Down

0 comments on commit 196ed1e

Please sign in to comment.