Skip to content

christophmeissner/pytest-pre-commit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

pytest-pre-commit

A simple pre-commit hook to run tests with pytest.

How to use?

Add this to your local .pre-commit-config.yaml:

# .pre-commit-config.yaml
- repo: https://github.com/christophmeissner/pytest-pre-commit
  rev: 1.0.0
  hooks:
  - id: pytest
    pass_filenames: false
    always_run: true

How to run?

To run the hook without commiting, run...

$ pre-commit run pytest -a

When the tests pass, this won't produce any further output.

If you want to see more verbose output, run...

$ pre-commit run pytest -a -v

Adding arguments to the invocation of pytest

You can pass arguments to the invocation of pytest by adding an args list to the hook config in .pre-commit-config.yaml, for example:

# .pre-commit-config.yaml
- repo: https://github.com/christophmeissner/pytest-pre-commit
  rev: 1.0.0
  hooks:
  - id: pytest
    pass_filenames: false
    always_run: true
    args:
      - "--durations=0"
      - "--last-failed"
      - "--last-failed-no-failures=all"
      - "--new-first"
      - "-rfEsxXp"
      - "-vvv"

... and/or you can add the pytest arguments for every test run in your pytest.ini file, for example like this:

# pytest.ini
[pytest]
minversion = 6.0
addopts = --durations=0 --last-failed --last-failed-no-failures all --new-first -rfEsxXp -vvv
testpaths =
    tests

For more information about pytest CLI arguments and how to invoke pytest, see pytest: How to invoke pytest and pytest: Complete pytest command-line flag reference.

About

pre-commit hook to run pytest

Resources

License

Stars

Watchers

Forks

Packages

No packages published