Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests with pre-commit on only the changed/affected files using pytest-testmon. #923

Closed
Tracked by #921
ns-rse opened this issue Oct 1, 2024 · 0 comments · Fixed by #926
Closed
Tracked by #921

Run tests with pre-commit on only the changed/affected files using pytest-testmon. #923

ns-rse opened this issue Oct 1, 2024 · 0 comments · Fixed by #926

Comments

@ns-rse
Copy link
Collaborator

ns-rse commented Oct 1, 2024

We should add a local job to .pre-commit-config.yaml to run pytest on only the files that have been changed or affected by changes using pytest-testmon.

.pre-commit-config.yaml

  - repo: local
    hooks:
      - id: pytest-testmon
        args: ["--rcfile=.pylintrc"]
        name: Pytest Monitor
        entry: pytest 
        language: system
        files: \.py$

pyproject.toml

Add pytest-testmon to the tests optional dependencies.

[project.optional-dependencies]
tests = [
  "pytest",
  "pytest-cov",
  "pytest-github-actions-annotate-failures",
  "pytest-mpl",
  "pytest-regtest",
  "pytest-testmon",
  "filetype",
]

docs/contributing.md

Detail in the docs/contributing.md how to setup and use the pytest-testmon database on initially cloning the repository.

.gitignore

Will probably have to ignore the .testdatamon from version control as it will be dependent on an individuals development stage.

ns-rse added a commit that referenced this issue Oct 1, 2024
Closes #923

A little more involved than I thought.

- Needed to use `files: \.py$` in the hook to restrict it to commits that contain changes to Python files.
- Had to remove the `--cov` option to `pytest` defined in `pyproject.toml` as the use of coverage forces the
  `--testmon-nocollect` option to be enabled which deactivates collection and writing of testmon data. Coverage is still
  explicitly run under GitHub Actions though so we will still get the coverage reports there.
- Rejigged documentation recommending installation of all `dev`/`tests`/`docs` dependencies.
- Added note on how to setup `pytest-testmon` database locally to documentation.
ns-rse added a commit that referenced this issue Oct 1, 2024
Closes #923

A little more involved than I thought.

- Needed to use `files: \.py$` in the hook to restrict it to commits that contain changes to Python files.
- Had to remove the `--cov` option to `pytest` defined in `pyproject.toml` as the use of coverage forces the
  `--testmon-nocollect` option to be enabled which deactivates collection and writing of testmon data. Coverage is still
  explicitly run under GitHub Actions though so we will still get the coverage reports there.
- Rejigged documentation recommending installation of all `dev`/`tests`/`docs` dependencies.
- Added note on how to setup `pytest-testmon` database locally to documentation.
- `pytest` pre-commit hook is excluded from `pre-commit.ci` as tests are already run elsewhere on the whole suite.
@ns-rse ns-rse closed this as completed Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant