Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve testing of charm libraries #76

Open
NucciTheBoss opened this issue Mar 3, 2023 · 0 comments
Open

Improve testing of charm libraries #76

NucciTheBoss opened this issue Mar 3, 2023 · 0 comments

Comments

@NucciTheBoss
Copy link
Contributor

Per our discussion on the dnf charm library pull request here #75 (comment), we realized that there is potentially a better way to launch tests without having to use pytest's built-in flag --ignore=... to ignore specific tests. In the discussion thread, it was suggested to use @pytest.mark.<test_suite> with pytest -m <test_suite>.

I also wanted to suggest potentially using cleantest for helping with the overhaul of the tests for the charm libraries. I noticed in the tox.ini file that there is a standalone integration environment for just setting up an LXD test instance:

[testenv:integration]
description = Build a LXD container for integration tests then run the tests
allowlist_externals =
lxc
bash
commands =
# Create a LXC container with the relevant packages installed
bash -c 'lxc launch -qe ubuntu:focal {[vars]lxd_name} -c=user.user-data="$(<{[vars]itst_dir}/test_setup.yaml)"'
# Wait for the cloud-init process to finish
lxc exec {[vars]lxd_name} -- bash -c "cloud-init status -w >/dev/null 2>&1"
# Copy all the files needed for integration testing
lxc file push -qp {toxinidir}/tox.ini {[vars]lxd_name}/{[vars]lxd_name}/
lxc file push -qp {toxinidir}/pyproject.toml {[vars]lxd_name}/{[vars]lxd_name}/
lxc file push -qpr {toxinidir}/lib {[vars]lxd_name}/{[vars]lxd_name}/
lxc file push -qpr {[vars]tst_dir} {[vars]lxd_name}/{[vars]lxd_name}/
# Run the tests
lxc exec {[vars]lxd_name} -- tox -c /{[vars]lxd_name}/tox.ini -e integration-tests {posargs}
commands_post =
-lxc stop {[vars]lxd_name}

cleantest can handle both bringing up and tearing down the Ubuntu test instance. This way the LXD logic does not have to live inside of tox.ini and the integration environment can be dedicated for just launching the integration tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant