Skip to content

Commit

Permalink
tools: Split unit and integration tests (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau authored Jan 26, 2023
1 parent 229ee11 commit 63fc646
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Empty file added tests/integration/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions tests/integration/test_init.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
"""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
Empty file added tests/unit/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion tests/test_init.py → tests/unit/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""Basic Starcraft package demo tests."""
"""Basic Starcraft package demo unit tests."""
from unittest import mock

from starcraft import hello
Expand Down
20 changes: 15 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 63fc646

Please sign in to comment.