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..4bda6350 --- /dev/null +++ b/.github/workflows/python-coverage.yml @@ -0,0 +1,48 @@ +name: python coverage + +on: + push: + branches: + - master + pull_request: {} + +jobs: + coverage: + runs-on: ubuntu-latest + + # Not intended for forks. + if: github.repository == 'optuna/optuna-dashboard' + + 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 + run: | + python -m pip install --progress-bar off --upgrade pip setuptools + pip install --progress-bar off .[optional] + pip install --progress-bar off .[test] + 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_dashboard -m pytest python_tests + coverage combine + coverage xml + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.xml + fail_ci_if_error: true diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 612ddb59..8fee4e44 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -45,7 +45,8 @@ jobs: # python_tests requires optuna>=3.0.0 since it imports FloatDistribution run: | python -m pip install --progress-bar off --upgrade pip setuptools - pip install streamlit boto3 moto[s3] pytest + pip install --progress-bar off .[optional] + pip install --progress-bar off .[test] pip install --progress-bar off "optuna>=3.0.0" pip install --progress-bar off . - run: pytest python_tests @@ -61,7 +62,8 @@ jobs: - name: Install dependencies run: | python -m pip install --progress-bar off --upgrade pip setuptools - pip install streamlit boto3 moto[s3] pytest + pip install --progress-bar off .[optional] + pip install --progress-bar off .[test] pip install --progress-bar off . python -m pip install --progress-bar off --upgrade git+https://github.com/optuna/optuna.git - run: pytest python_tests diff --git a/.gitignore b/.gitignore index 50ea6367..49c137e0 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 d9c0082c..0555f701 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,18 @@ docs = [ "sphinx_rtd_theme", ] +test = [ + "coverage", + "pytest", + "moto[s3]", +] + +optional = [ + "streamlit", + "boto3", +] + + [project.scripts] optuna-dashboard = "optuna_dashboard._cli:main"