Skip to content

Commit

Permalink
Merge pull request #174 from AlanCoding/good_test_fixes
Browse files Browse the repository at this point in the history
Apply conservative test fixes

Reviewed-by: https://github.com/apps/ansible-zuul
  • Loading branch information
ansible-zuul[bot] authored Jan 12, 2021
2 parents 2118e25 + 568f3a6 commit fcc0312
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 9 additions & 1 deletion test/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ def run(args, *a, allow_error=False, **kw):

kw.setdefault("env", os.environ.copy()).update({"LANG": "en_US.UTF-8"})

for i, arg in enumerate(args):
if not isinstance(arg, str):
raise pytest.fail(
f'Argument {arg} in {i} position is not string, args:\n{args}'
)

try:
ret = CompletedProcessProxy(subprocess.run(args, shell=True, *a, **kw))
except subprocess.CalledProcessError as err:
if not allow_error:
pytest.fail(
# Previously used pytest.fail here, but that missed some error details
print(
f"Running {err.cmd} resulted in a non-zero return code: {err.returncode} - stdout: {err.stdout}, stderr: {err.stderr}"
)
raise
err.rc = err.returncode # lazyily make it look like a CompletedProcessProxy
return err

Expand Down
7 changes: 4 additions & 3 deletions test/integration/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def pytz(self, cli_class, container_runtime, ee_tag_class, data_dir, tmpdir_fact
r = cli_class(
f'ansible-builder build -c {bc_folder} -f {ee_def} -t {ee_tag_class} --container-runtime {container_runtime} -v 3'
)
assert 'Collecting pytz' in r.stdout, r.stdout
# Because of test multi-processing, this may or may not use cache, so allow either
assert 'RUN /output/install-from-bindep && rm -rf /output/wheels' in r.stdout, r.stdout
return (ee_tag_class, bc_folder)

def test_has_pytz(self, cli, container_runtime, pytz):
Expand All @@ -188,7 +189,7 @@ def test_build_layer_reuse(self, cli, container_runtime, data_dir, pytz):
r = cli(
f'ansible-builder build -c {bc_folder} -f {ee_def} -t {ee_tag} --container-runtime {container_runtime} -v 3'
)
assert 'Collecting pytz (from -r /build/' not in r.stdout, r.stdout
assert 'Collecting pytz' not in r.stdout, r.stdout
assert 'requirements_combined.txt is already up-to-date' in r.stdout, r.stdout
stdout_no_whitespace = r.stdout.replace('--->', '-->').replace('\n', ' ').replace(' ', ' ').replace(' ', ' ')
assert 'RUN /output/install-from-bindep --> Using cache' in stdout_no_whitespace, r.stdout
assert 'RUN /output/install-from-bindep && rm -rf /output/wheels --> Using cache' in stdout_no_whitespace, r.stdout

0 comments on commit fcc0312

Please sign in to comment.