0

私は pytest カバレッジを使用しており、次のコマンド ラインにテスト スクリプトがあり、カバレッジ レポートを生成します。

"""Manager script to run the commands on the Flask API."""
import os
import click
from api import create_app
from briqy.logHelper import b as logger
import pytest

app = create_app()


@app.cli.command("tests")
@click.argument("option", required=False)
def run_test_with_option(option: str = None):
    from subprocess import run
    from shlex import split

    if option is None:
        raise SystemExit(
            pytest.main(
                [
                    "--disable-pytest-warnings",
                    "--cov=lib",
                    "--cov-config=.coveragerc",
                    "--cov-report=term",
                    "--cov-report=xml",
                    "--cov-report=html",
                    "--junitxml=./tests/coverage/junit.xml",
                    "--cov-append",
                    "--no-cov-on-fail",
                ]
            )
        )
    elif option == "watch":
        run(
            split(
                'ptw --runner "python3 -m pytest tests --durations=5 '
                '--disable-pytest-warnings"'
            )
        )
    elif option == "debug":
        run(
            split(
                'ptw --pdb --runner "python3 -m pytest tests --durations=5 '
                '--disable-pytest-warnings"'
            )
        )


if __name__ == "__main__":
    HOST = os.getenv("FLASK_RUN_HOST", default="127.0.0.1")
    PORT = os.getenv("FLASK_RUN_PORT", default=5000)
    DEBUG = os.getenv("FLASK_DEBUG", default=False)

    app.run(
        host=HOST,
        port=PORT,
        debug=DEBUG,
    )

    if bool(DEBUG):
        logger.info(f"Flask server is running in {os.getenv('ENV')}")

ただし、テストを実行した後、テストによって明らかになったファイルの上にインポートが表示されます。それらの覆われていない行を取り除く方法を知っている人はいますか?

4

2 に答える 2