Files
openfe/openfecli/commands/test.py
Mike Henry d2e84eef9e Exit with return value from pytest.main (#1297)
* exit with the return value of pytest.main when running openfe test

* always restore env
2025-05-27 08:27:04 -07:00

46 lines
1.3 KiB
Python

import click
from openfecli import OFECommandPlugin
import sys
import pytest
import os
from openfecli.utils import write
@click.command(
"test",
short_help="Run the OpenFE test suite"
)
@click.option('--long', is_flag=True, default=False,
help="Run additional tests (takes much longer)")
def test(long):
"""
Run the OpenFE test suite. This first checks that OpenFE is correctly
imported, and then runs the main test suite, which should take several
minutes. If given the ``--long`` flag, this will include several tests
that take significantly longer, but ensure that we're able to fully run
in your environment.
A successful run will include tests that pass, skip, or "xfail". In many
terminals, these show as green or yellow. Warnings are not a concern.
However, You should not see anything that fails or errors (red).
"""
try:
old_env = dict(os.environ)
os.environ["OFE_SLOW_TESTS"] = str(long)
write("Testing can import....")
import openfe
write("Running the main package tests")
return_value = pytest.main(["-v", "--pyargs", "openfe", "--pyargs", "openfecli"])
finally:
os.environ.clear()
os.environ.update(old_env)
sys.exit(return_value)
PLUGIN = OFECommandPlugin(
test,
"Miscellaneous",
requires_ofe=(0, 7,5)
)