From 63fc646670125a24e3ee57ec59852bf203b6a15c Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Wed, 25 Jan 2023 19:32:57 -0500 Subject: [PATCH] tools: Split unit and integration tests (#7) --- pyproject.toml | 4 +--- tests/integration/__init__.py | 0 tests/integration/test_init.py | 25 +++++++++++++++++++++++++ tests/unit/__init__.py | 0 tests/{ => unit}/test_init.py | 2 +- tox.ini | 20 +++++++++++++++----- 6 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 tests/integration/__init__.py create mode 100644 tests/integration/test_init.py create mode 100644 tests/unit/__init__.py rename tests/{ => unit}/test_init.py (95%) diff --git a/pyproject.toml b/pyproject.toml index 053d757208..31b4370c93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,12 +55,10 @@ line_length = 88 minversion = "7.0" testpaths = "tests" xfail_strict = true -addopts = [ - "--cov", -] [tool.coverage.run] branch = true +parallel = true omit = ["tests/**"] [tool.coverage.report] diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/test_init.py b/tests/integration/test_init.py new file mode 100644 index 0000000000..879210b715 --- /dev/null +++ b/tests/integration/test_init.py @@ -0,0 +1,25 @@ +# This file is part of starcraft. +# +# Copyright 2023 Canonical Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License version 3, as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, +# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +"""Basic Starcraft package demo integration tests.""" +import subprocess + + +def test_cli(): + expected = "Hello *craft team!\n" + + actual = subprocess.check_output(["starcraft-hello"], text=True) + + assert expected == actual diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/test_init.py b/tests/unit/test_init.py similarity index 95% rename from tests/test_init.py rename to tests/unit/test_init.py index 61c5974195..78d4114a4d 100644 --- a/tests/test_init.py +++ b/tests/unit/test_init.py @@ -13,7 +13,7 @@ # # You should have received a copy of the GNU General Public License along # with this program. If not, see . -"""Basic Starcraft package demo tests.""" +"""Basic Starcraft package demo unit tests.""" from unittest import mock from starcraft import hello diff --git a/tox.ini b/tox.ini index 543c6494e8..d7007ccd65 100644 --- a/tox.ini +++ b/tox.ini @@ -27,15 +27,25 @@ env_tmp_dir = {user_tmp_dir:{env:XDG_RUNTIME_DIR:{work_dir}}}/tox_tmp/{env_name} set_env = TMPDIR={env_tmp_dir} -[testenv:test-{py38,py39,py310,py311,py312}] # Configuration for all tests using pytest -description = Run tests with pytest +[test] # Base configuration for unit and integration tests package = sdist extras = dev -labels = - py38, py310, py311: tests, unit-tests allowlist_externals = mkdir commands_pre = mkdir -p results -commands = pytest {tty:--color=yes} --cov-report=xml:results/coverage-{env_name}.xml --junit-xml=results/test-results-{env_name}.xml {posargs} + +[testenv:test-{py38,py39,py310,py311,py312}] # Configuration for all tests using pytest +base = testenv, test +description = Run unit tests with pytest +labels = + py38, py310, py311: tests, unit-tests +commands = pytest {tty:--color=yes} --cov --cov-report=xml:results/coverage-{env_name}.xml --junit-xml=results/test-results-{env_name}.xml tests/unit {posargs} + +[testenv:integration-{py38,py39,py310,py311,py312}] +base = testenv, test +description = Run integration tests with pytest +labels = + py38, py310, py311: tests, integration-tests +commands = pytest {tty:--color=yes} --junit-xml=results/test-results-{env_name}.xml tests/integration {posargs} [lint] # Standard linting configuration skip_install = true