Skip to content

Commit

Permalink
Fix running multiple test commands via invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
lang-m committed May 21, 2022
1 parent a01f125 commit 8142492
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
def unittest(c):
"""Run unittests."""
import micromagnetictests

result = micromagnetictests.test()
raise Exit(code=result)

Expand All @@ -34,13 +33,7 @@ def coverage(c):
def docs(c):
"""Run doctests."""
result = pytest.main(
[
"-v",
"--doctest-modules",
"--ignore",
"micromagnetictests/tests",
"micromagnetictests",
]
["-v", "--doctest-modules", "--ignore", "micromagnetictests/tests", "micromagnetictests"]
)
raise Exit(code=result)

Expand All @@ -52,9 +45,16 @@ def ipynb(c):
raise Exit(code=result)


@task(unittest, docs, ipynb)
@task
def all(c):
"""Run all tests."""
for cmd in (unittest, docs, ipynb):
try:
cmd(c)
except Exit as e:
if e.code != pytest.ExitCode.OK:
raise e
raise Exit(code=pytest.ExitCode.OK)


test_collection.add_task(unittest)
Expand Down Expand Up @@ -99,15 +99,19 @@ def release(c):
raise Exit("Working tree is not clean. Aborting.")

# run all tests
all(c)
try:
all(c)
except Exit as e:
if e.code != pytest.ExitCode.OK:
raise e

version = iniconfig.IniConfig("setup.cfg").get("metadata", "version")
# sanity checks while we have two places containing the version.
with open("pyproject.toml", "rb") as f:
toml_version = tomli.load(f)["project"]["version"]
assert (
toml_version == version
), "Different versions in pyproject.toml and setup.cfg. Aborting."
assert toml_version == version, (
"Different versions in pyproject.toml and setup.cfg. Aborting."
)

c.run(f"git tag {version}") # fails if the tag exists
c.run("git tag -f latest") # `latest` tag for binder
Expand Down

0 comments on commit 8142492

Please sign in to comment.