8000 Drop use of pytest-helpers-namespace (#3195) · ansible/molecule@769658d · GitHub
[go: up one dir, main page]

Skip to content

Commit 769658d

Browse files
authored
Drop use of pytest-helpers-namespace (#3195)
Related: saltstack/pytest-helpers-namespace#10
1 parent 646cd29 commit 769658d

File tree

10 files changed

+71
-68
lines changed

10 files changed

+71
-68
lines changed

conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import pytest
88

9-
pytest_plugins = ["helpers_namespace"]
10-
119

1210
@pytest.fixture(scope="session", autouse=True)
1311
def environ():

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ test =
112112

113113
pexpect >= 4.8.0, < 5
114114
pytest-cov >= 2.10.1
115-
pytest-helpers-namespace >= 2019.1.8
116115
pytest-html >= 3.0.0
117116
pytest-mock >= 3.3.1
118117
pytest-plus >= 0.2

src/molecule/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,12 @@ def _validate(self):
433433
util.sysexit_with_message(msg)
434434

435435

436-
def molecule_directory(path):
436+
def molecule_directory(path: str) -> str:
437437
"""Return directory of the current scenario."""
438438
return os.path.join(path, MOLECULE_DIRECTORY)
439439

440440

441-
def molecule_file(path):
441+
def molecule_file(path: str) -> str:
442442
"""Return file path of current scenario."""
443443
return os.path.join(path, MOLECULE_FILE)
444444

src/molecule/test/conftest.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line c A85A hange
@@ -74,33 +74,27 @@ def resources_folder_path():
7474
return resources_folder_path
7575

7676

77-
@pytest.helpers.register
78-
def molecule_project_directory():
77+
def molecule_project_directory() -> str:
7978
return os.getcwd()
8079

8180

82-
@pytest.helpers.register
83-
def molecule_directory():
81+
def molecule_directory() -> str:
8482
return config.molecule_directory(molecule_project_directory())
8583

8684

87-
@pytest.helpers.register
88-
def molecule_scenario_directory():
85+
def molecule_scenario_directory() -> str:
8986
return os.path.join(molecule_directory(), "default")
9087

9188

92-
@pytest.helpers.register
93-
def molecule_file():
89+
def molecule_file() -> str:
9490
return get_molecule_file(molecule_scenario_directory())
9591

9692

97-
@pytest.helpers.register
98-
def get_molecule_file(path):
93+
def get_molecule_file(path: str) -> str:
9994
return config.molecule_file(path)
10095

10196

102-
@pytest.helpers.register
103-
def molecule_ephemeral_directory(_fixture_uuid):
97+
def molecule_ephemeral_directory(_fixture_uuid) -> str:
10498
project_directory = "test-project-{}".format(_fixture_uuid)
10599
scenario_name = "test-instance"
106100

src/molecule/test/functional/conftest.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
import shutil
2424
import subprocess
2525
from subprocess import PIPE
26+
from typing import Optional
2627

2728
import pexpect
2829
import pkg_resources
2930
import pytest
3031

3132
from molecule import logger, util
3233
from molecule.config import ansible_version
33-
from molecule.test.conftest import change_dir_to
34+
from molecule.test.conftest import change_dir_to, molecule_directory
3435
from molecule.text import strip_ansi_color
3536
from molecule.util import run_command
3637

@@ -92,7 +93,6 @@ def skip_test(request, driver_name):
9293
pass
9394

9495

95-
@pytest.helpers.register
9696
def idempotence(scenario_name):
9797
cmd = ["molecule", "create", "--scenario-name", scenario_name]
9898
assert run_command(cmd).returncode == 0
@@ -104,31 +104,29 @@ def idempotence(scenario_name):
104104
assert run_command(cmd).returncode == 0
105105

106106

107-
@pytest.helpers.register
108107
def init_role(temp_dir, driver_name):
109108
role_directory = os.path.join(temp_dir.strpath, "myorg.myrole")
110109

111110
cmd = ["molecule", "init", "role", "myorg.myrole", "--driver-name", driver_name]
112111
assert run_command(cmd).returncode == 0
113-
pytest.helpers.metadata_lint_update(role_directory)
112+
metadata_lint_update(role_directory)
114113

115114
with change_dir_to(role_directory):
116115
cmd = ["molecule", "test", "--all"]
117116
assert run_command(cmd).returncode == 0
118117

119118

120-
@pytest.helpers.register
121119
def init_scenario(temp_dir, driver_name):
122120
# Create role
123121
role_directory = os.path.join(temp_dir.strpath, "test-init")
124122
cmd = ["molecule", "init", "role", "test-init", "--driver-name", driver_name]
125123
assert run_command(cmd).returncode == 0
126-
pytest.helpers.metadata_lint_update(role_directory)
124+
metadata_lint_update(role_directory)
127125

128126
with change_dir_to(role_directory):
129127
# Create scenario
130-
molecule_directory = pytest.helpers.molecule_directory()
131-
scenario_directory = os.path.join(molecule_directory, "test-scenario")
128+
molecule_dir = molecule_directory()
129+
scenario_directory = os.path.join(molecule_dir, "test-scenario")
132130

133131
cmd = [
134132
"molecule",
@@ -148,17 +146,15 @@ def init_scenario(temp_dir, driver_name):
148146
assert run_command(cmd).returncode == 0
149147

150148

151-
@pytest.helpers.register
152-
def metadata_lint_update(role_directory):
149+
def metadata_lint_update(role_directory: str) -> None:
153150
# By default, ansible-lint will fail on newly-created roles because the
154151
# fields in this file have not been changed from their defaults. This is
155152
# good because molecule should create this file using the defaults, and
156153
# users should receive feedback to change these defaults. However, this
157154
# blocks the testing of 'molecule init' itself, so ansible-lint should
158155
# be configured to ignore these metadata lint errors.
159-
ansible_lint_src = os.path.join(
160-
os.path.dirname(util.abs_path(__file__)), ".ansible-lint"
161-
)
156+
dirname = os.path.dirname(os.path.abspath(__file__))
157+
ansible_lint_src = os.path.join(dirname, ".ansible-lint")
162158
shutil.copy(ansible_lint_src, role_directory)
163159

164160
# Explicitly lint here to catch any unexpected lint errors before
@@ -170,8 +166,7 @@ def metadata_lint_update(role_directory):
170166
assert run_command(cmd).returncode == 0
171167

172168

173-
@pytest.helpers.register
174-
def list(x):
169+
def list_cmd(x):
175170
cmd = ["molecule", "list"]
176171
result = run_command(cmd)
177172
assert result.returncode == 0
@@ -181,7 +176,6 @@ def list(x):
181176
assert l in out
182177

183178

184-
@pytest.helpers.register
185179
def list_with_format_plain(x):
186180
cmd = ["molecule", "list", "--format", "plain"]
187181
result = util.run_command(cmd)
@@ -191,7 +185,6 @@ def list_with_format_plain(x):
191185
assert l in out
192186

193187

194-
@pytest.helpers.register
195188
def login(login_args, scenario_name="default"):
196189
cmd = ["molecule", "destroy", "--scenario-name", scenario_name]
197190
assert run_command(cmd).returncode == 0
@@ -212,8 +205,7 @@ def login(login_args, scenario_name="default"):
212205
child.sendline("exit")
213206

214207

215-
@pytest.helpers.register
216-
def test(driver_name, scenario_name="default", parallel=False):
208+
def run_test(driver_name, scenario_name="default", parallel=False):
217209
cmd = ["molecule", "test", "--scenario-name", scenario_name]
218210
if driver_name != "delegated":
219211
if scenario_name is None:
@@ -224,7 +216,6 @@ def test(driver_name, scenario_name="default", parallel=False):
224216
assert run_command(cmd).returncode == 0
225217

226218

227-
@pytest.helpers.register
228219
def verify(scenario_name="default"):
229220
cmd = ["molecule", "create", "--scenario-name", scenario_name]
230221
assert run_command(cmd).returncode == 0
@@ -236,17 +227,16 @@ def verify(scenario_name="default"):
236227
assert run_command(cmd).returncode == 0
237228

238229

239-
def get_docker_executable():
230+
def get_docker_executable() -> Optional[str]:
240231
return shutil.which("docker")
241232

242233

243234
def get_virtualbox_executable():
244235
return shutil.which("VBoxManage")
245236

246237

247-
@pytest.helpers.register
248238
@util.lru_cache()
249-
def supports_docker():
239+
def supports_docker() -> bool:
250240
docker = get_docker_executable()
251241
if docker:
252242
result = subprocess.run([docker, "info"], stdout=PIPE, universal_newlines=True)

src/molecule/test/functional/test_command.py

Lines changed: 24 additions & 10 deletions
162
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,19 @@
1818
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
# DEALINGS IN THE SOFTWARE.
2020

21-
import pytest
21+
from typing import Optional
2222

23+
import pytest
24+
from pytest import FixtureRequest
25+
26+
from molecule.test.functional.conftest import (
27+
idempotence,
28+
init_role,
29+
init_scenario,
30+
list_with_format_plain,
31+
run_test,
32+
verify,
33+
)
2334
from molecule.util import run_command
2435

2536

@@ -37,8 +48,11 @@ def scenario_name(request):
3748

3849

3950
@pytest.fixture
40-
def driver_name(request):
41-
return request.param
51+
def driver_name(request: FixtureRequest) -> Optional[str]:
52+
try:
53+
return request.param
54+
except AttributeError:
55+
return None
4256

4357

4458
@pytest.mark.extensive
@@ -146,19 +160,19 @@ def test_command_destroy(scenario_to_test, with_scenario, scenario_name):
146160
indirect=["scenario_to_test", "driver_name", "scenario_name"],
147161
)
148162
def test_command_idempotence(scenario_to_test, with_scenario, scenario_name):
149-
pytest.helpers.idempotence(scenario_name)
163+
idempotence(scenario_name)
150164

151165

152166
@pytest.mark.parametrize("driver_name", [("delegated")], indirect=["driver_name"])
153167
@pytest.mark.xfail(reason="https://github.com/ansible-community/molecule/issues/3171")
154168
def test_command_init_role(temp_dir, driver_name, skip_test):
155-
pytest.helpers.init_role(temp_dir, driver_name)
169+
init_role(temp_dir, driver_name)
156170

157171

158172
@pytest.mark.parametrize("driver_name", [("delegated")], indirect=["driver_name"])
159173
@pytest.mark.xfail(reason="https://github.com/ansible-community/molecule/issues/3171")
160174
def test_command_init_scenario(temp_dir, driver_name, skip_test):
161-
pytest.helpers.init_scenario(temp_dir, driver_name)
175+
init_scenario(temp_dir, driver_name)
176

163177

164178
@pytest.mark.extensive
@@ -186,7 +200,7 @@ def test_command_lint(scenario_to_test, with_scenario, scenario_name):
186200
indirect=["scenario_to_test", "driver_name"],
187201
)
188202
def test_command_list_with_format_plain(scenario_to_test, with_scenario, expected):
189-
pytest.helpers.list_with_format_plain(expected)
203+
list_with_format_plain(expected)
190204

191205

192206
# @pytest.mark.parametrize(
@@ -202,7 +216,7 @@ def test_command_list_with_format_plain(scenario_to_test, with_scenario, expecte
202216
# indirect=["scenario_to_test", "driver_name", "scenario_name"],
203217
# )
204218
# def test_command_login(scenario_to_test, with_scenario, login_args, scenario_name):
205-
# pytest.helpers.login(login_args, scenario_name)
219+
# login(login_args, scenario_name)
206220

207221

208222
@pytest.mark.extensive
@@ -255,7 +269,7 @@ def test_command_syntax(scenario_to_test, with_scenario, scenario_name):
255269
indirect=["scenario_to_test", "driver_name", "scenario_name"],
256270
)
257271
def test_command_test(scenario_to_test, with_scenario, scenario_name, driver_name):
258-
pytest.helpers.test(driver_name, scenario_name)
272+
run_test(driver_name, scenario_name)
259273

260274

261275
@pytest.mark.extensive
@@ -267,4 +281,4 @@ def test_command_test(scenario_to_test, with_scenario, scenario_name, driver_nam
267281
indirect=["scenario_to_test", "driver_name", "scenario_name"],
268282
)
269283
def test_command_verify(scenario_to_test, with_scenario, scenario_name):
270-
pytest.helpers.verify(scenario_name)
284+
verify(scenario_name)

src/molecule/test/unit/conftest.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,25 @@
2424
import shutil
2525
from pathlib import Path
2626
from subprocess import CompletedProcess
27+
from typing import Any, Tuple
2728
from uuid import uuid4
2829

2930
import pytest
3031

3132
from molecule import config, util
33+
from molecule.test.conftest import (
34+
molecule_directory,
35+
molecule_ephemeral_directory,
36+
molecule_file,
37+
molecule_scenario_directory,
38+
)
3239

3340

34-
@pytest.helpers.register
35-
def write_molecule_file(filename, data):
41+
def write_molecule_file(filename: str, data: Any) -> None:
3642
util.write_file(filename, util.safe_dump(data))
3743

3844

39-
@pytest.helpers.register
40-
def os_split(s):
45+
def os_split(s: str) -> Tuple[str, ...]:
4146
rest, tail = os.path.split(s)
4247
if rest in ("", os.path.sep):
4348
return (tail,)
@@ -109,12 +114,12 @@ def molecule_data(
109114

110115
@pytest.fixture
111116
def molecule_directory_fixture(temp_dir):
112-
return pytest.helpers.molecule_directory()
117+
return molecule_directory()
113118

114119

115120
@pytest.fixture
116121
def molecule_scenario_directory_fixture(molecule_directory_fixture):
117-
path = pytest.helpers.molecule_scenario_directory()
122+
path = molecule_scenario_directory()
118123
if not os.path.isdir(path):
119124
os.makedirs(path)
120125

@@ -123,7 +128,7 @@ def molecule_scenario_directory_fixture(molecule_directory_fixture):
123128

124129
@pytest.fixture
125130
def molecule_ephemeral_directory_fixture(molecule_scenario_directory_fixture):
126-
path = pytest.helpers.molecule_ephemeral_directory(str(uuid4()))
131+
path = molecule_ephemeral_directory(str(uuid4()))
127132
if not os.path.isdir(path):
128133
os.makedirs(path)
129134
yield
@@ -134,7 +139,7 @@ def molecule_ephemeral_directory_fixture(molecule_scenario_directory_fixture):
134139
def molecule_file_fixture(
135140
molecule_scenario_directory_fixture, molecule_ephemeral_directory_fixture
136141
):
137-
return pytest.helpers.molecule_file()
142+
return molecule_file()
138143

139144

140145
@pytest.fixture
@@ -144,7 +149,7 @@ def config_instance(
144149
mdc = copy.deepcopy(molecule_data)
145150
if hasattr(request, "param"):
146151
mdc = util.merge_dicts(mdc, request.getfixturevalue(request.param))
147-
pytest.helpers.write_molecule_file(molecule_file_fixture, mdc)
152+
write_molecule_file(molecule_file_fixture, mdc)
148153
c = config.Config(molecule_file_fixture)
149154
c.command_args = {"subcommand": "test"}
150155

0 commit comments

Comments
 (0)
0