Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

Commit 65a934a

Browse files
authored
Merge pull request #5 from pycontribs/devel
Minor improvements
2 parents 9a2a802 + 8d08233 commit 65a934a

File tree

7 files changed

+45
-17
lines changed

7 files changed

+45
-17
lines changed

ansible.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[defaults]
2+
ansible_python_interpreter = auto_silent
3+
retry_files_enabled = False

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
addopts=-p no:flaky

pytest_molecule.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ def pytest_collect_file(parent, path):
3838

3939
class MoleculeFile(pytest.File):
4040
def collect(self):
41-
yield MoleculeItem("", self)
41+
yield MoleculeItem('test', self)
42+
43+
def __str__(self):
44+
return str(self.fspath.relto(os.getcwd()))
4245

4346

4447
class MoleculeItem(pytest.Item):
@@ -50,21 +53,36 @@ def runtest(self):
5053
cwd = os.path.abspath(os.path.join(self.fspath.dirname, '../..'))
5154
scenario = folders[-1]
5255
role = folders[-3] # noqa
53-
54-
cmd = ['python', '-m', 'molecule', 'test', '-s', scenario]
56+
cmd = [sys.executable, '-m', 'molecule', self.name, '-s', scenario]
5557
print("running: %s (from %s)" % (" " .join(cmd), cwd))
56-
# Workaround for STDOUT/STDERR line ordering issue:
57-
# https://github.com/pytest-dev/pytest/issues/5449
58-
p = subprocess.Popen(
59-
cmd,
60-
cwd=cwd,
61-
stdout=subprocess.PIPE,
62-
stderr=subprocess.STDOUT,
63-
universal_newlines=True)
64-
for line in p.stdout:
65-
print(line, end="")
66-
p.wait()
67-
assert p.returncode == 0
58+
59+
try:
60+
# Workaround for STDOUT/STDERR line ordering issue:
61+
# https://github.com/pytest-dev/pytest/issues/5449
62+
p = subprocess.Popen(
63+
cmd,
64+
cwd=cwd,
65+
stdout=subprocess.PIPE,
66+
stderr=subprocess.STDOUT,
67+
universal_newlines=True)
68+
for line in p.stdout:
69+
print(line, end="")
70+
p.wait()
71+
if p.returncode != 0:
72+
pytest.fail(
73+
"Error code %s returned by: %s" % (
74+
p.returncode, " ".join(cmd)),
75+
pytrace=False)
76+
except Exception as e:
77+
pytest.fail(
78+
"Exception %s returned by: %s" % (e, " ".join(cmd)),
79+
pytrace=False)
80+
81+
def reportinfo(self):
82+
return self.fspath, 0, "usecase: %s" % self.name
83+
84+
def __str__(self):
85+
return self.name
6886

6987

7088
class MoleculeException(Exception):

tests/roles/myrole/molecule/default/molecule.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
driver:
33
name: docker
4-
log: true
4+
55
platforms:
66

77
- name: centos7-master
@@ -13,12 +13,14 @@ provisioner:
1313
name: ansible
1414
env:
1515
ANSIBLE_STDOUT_CALLBACK: yaml
16-
ANSIBLE_VERBOSITY: "2"
16+
log: true
17+
1718
scenario:
1819
test_sequence:
1920
- destroy
2021
- create
2122
- converge
2223
- destroy
24+
2325
lint:
2426
enabled: false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../default/molecule.yml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../default/playbook.yml

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ deps =
1010
pytest-html>=1.21.0
1111
selinux>=0.1.5rc1
1212
commands =
13+
pytest --collect-only -q
1314
pytest --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} {posargs:tests}
1415
setenv =
1516
ANSIBLE_FORCE_COLOR={env:ANSIBLE_FORCE_COLOR:1}

0 commit comments

Comments
 (0)