From 08a66edc8d7c8d01e807ed79a812aa9cc409ca68 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sat, 29 Jul 2023 15:32:42 +0900 Subject: [PATCH] Add configuration for coverage --- .coveragerc | 3 ++ .github/workflows/python-coverage.yml | 43 +++++++++++++++++++++++++++ .gitignore | 5 ++++ pyproject.toml | 6 ++++ 4 files changed, 57 insertions(+) create mode 100644 .coveragerc create mode 100644 .github/workflows/python-coverage.yml diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..26e44f99 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,3 @@ +[run] +concurrency = multiprocessing,thread +source = optuna_dashboard/ diff --git a/.github/workflows/python-coverage.yml b/.github/workflows/python-coverage.yml new file mode 100644 index 00000000..290c6826 --- /dev/null +++ b/.github/workflows/python-coverage.yml @@ -0,0 +1,43 @@ +name: python coverage + +on: + push: + branches: + - master + pull_request: {} + +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + architecture: x64 + + - name: Install dependencies + # python_tests requires optuna>=3.0.0 since it imports FloatDistribution + run: | + python -m pip install --progress-bar off --upgrade pip setuptools + pip install --progress-bar off "optuna>=3.0.0" + pip install --progress-bar off . + echo 'import coverage; coverage.process_startup()' > sitecustomize.py + + - name: Tests + env: + PYTHONPATH: . # To invoke sitecutomize.py + COVERAGE_PROCESS_START: .coveragerc # https://coverage.readthedocs.io/en/6.4.1/subprocess.html + COVERAGE_COVERAGE: yes # https://github.com/nedbat/coveragepy/blob/65bf33fc03209ffb01bbbc0d900017614645ee7a/coverage/control.py#L255-L261 + run: | + coverage run --source=optuna -m pytest tests -m "not skip_coverage and not slow" + coverage combine + coverage xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + file: ./coverage.xml diff --git a/.gitignore b/.gitignore index dde468fc..d530dc27 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,11 @@ docs/_generated/ rustlib/target/ rustlib/pkg/ +# Test +.coverage +.coverage.* +coverage.xml + # Others .envrc .idea/ diff --git a/pyproject.toml b/pyproject.toml index be4a18e0..93d24743 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,12 @@ dependencies = [ ] dynamic = ["version"] +[project.optional-dependencies] +test = [ + "coverage", + "pytest", +] + [project.scripts] optuna-dashboard = "optuna_dashboard._cli:main"