Commit 95efdfba authored by Duncan Macleod's avatar Duncan Macleod

ci: use pytest for all testing

allows simple uploads of test reports
parent 2ef4b2d4
Pipeline #59446 failed with stages
in 67 minutes and 8 seconds
......@@ -96,22 +96,23 @@ render:osx:
done
# copy test files into place
- mkdir -pv test
- find packages
-name "*.py"
-o -name "*.sh"
| xargs -I{} cp -v {} test/
- find packages -name "*.py" | xargs -I{} cp -v {} test/
- cd test
# test
# FIXME: once the branches are set up, we can probably get
# away with only testing the environment for the
# target branch, for now we test everything
- mkdir -p ${CI_PROJECT_DIR}/test-reports
- |
for ymlf in ${ENV_PATH}/*.yaml; do
NAME=$(basename ${ymlf} .yaml);
conda install --name=${NAME} pytest;
conda activate ${NAME};
python ${ENV_PATH}/${NAME}-test-imports.py;
bash ${ENV_PATH}/${NAME}-test-commands.sh;
python -m pytest ${ENV_PATH}/${NAME}-test-*.py -v --junitxml=${CI_PROJECT_DIR}/test-reports/${NAME}.xml;
done
artifacts:
reports:
junit: test-reports/*.xml
build-and-test:linux:
<<: *build-and-test
......
......@@ -43,19 +43,34 @@ IGNORE = {
TEST_TEMPLATE = {
"imports": """
#!/usr/bin/env python{{ python_version }}
# -*- coding: utf-8 -*-
import importlib
import pytest
@pytest.mark.parametrize("module", [
{% for item in imports %}
print("import: '{{ item }}'")
import {{ item }}
{% endfor %}
"{{ item }}",{% endfor %}
])
def test_import(module):
importlib.import_module(module)
""".strip(),
"commands": """
#!/bin/bash
#!/usr/bin/env python{{ python_version }}
# -*- coding: utf-8 -*-
import os
import subprocess
import pytest
set -ex
@pytest.mark.parametrize("command", [
{% for item in commands %}
{{ item }}
{% endfor %}
exit 0
\"\"\"{{ item|replace('"', '\\\\"') }}\"\"\",{% endfor %}
])
def test_command(command):
subprocess.check_call(command, shell=True, env=os.environ)
""".strip(),
}
......@@ -321,8 +336,7 @@ for pyv in environments:
# write tests
for test, template in TEST_TEMPLATE.items():
ext = "py" if test == "imports" else "sh"
testpath = envdir / "{}-test-{}.{}".format(name, test, ext)
testpath = envdir / "{}-test-{}.py".format(name, test)
with testpath.open("w") as out:
print(
jinja2.Template(template).render(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment