Skip to content

Commit

Permalink
test: watch modified files with pytest-watch and pytest-testmon
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed Apr 27, 2021
1 parent aaf08ae commit 4faab57
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ ENV/

# macOS
.DS_Store

# pytest-testmon
.testmondata
89 changes: 81 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ pytest-cov = { version = "*", optional = true }
testfixtures = { version = "*", optional = true }
freezegun = { version = "*", optional = true }
responses = { version = "*", optional = true }
pytest-testmon = { version = "*", optional = true }
pytest-watch = { version = "*", optional = true }
sphinx = { version = "*", optional = true }
sphinx_rtd_theme = { version = "*", optional = true }
sphobjinv = { version = "*", optional = true }
Expand All @@ -81,7 +83,7 @@ cachy = "*"

[tool.poetry.extras]
lint = ["pylint"]
test = ["pytest", "pytest-cov", "testfixtures", "responses", "freezegun"]
test = ["pytest", "pytest-cov", "testfixtures", "responses", "freezegun", "pytest-testmon", "pytest-watch"]
doc = ["sphinx", "sphinx_rtd_theme", "sphobjinv"]

[tool.poetry.dev-dependencies]
Expand Down
28 changes: 18 additions & 10 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Invoke targets.
Helpful docs:
- http://www.pyinvoke.org/
- http://docs.pyinvoke.org/en/stable/api/runners.html#invoke.runners.Runner.run
- https://www.pyinvoke.org/
- https://docs.pyinvoke.org/en/stable/api/runners.html#invoke.runners.Runner.run
"""
import sys
from configparser import ConfigParser
Expand Down Expand Up @@ -115,10 +115,20 @@ def update(ctx, deps=True, hooks=False):
install(ctx, deps, hooks)


@task(help={"coverage": "Run the HTML coverage report", "browse": "Browse the HTML coverage report"})
def test(ctx, coverage=False, browse=False):
@task(
help={
"coverage": "Run the HTML coverage report",
"browse": "Browse the HTML coverage report",
"watch": "Watch modified files and run tests with testmon",
}
)
def test(ctx, coverage=False, browse=False, watch=False):
"""Run tests and coverage using the commands from tox config."""
tox = ToxCommands()
if watch:
ctx.run('poetry run ptw --runner "pytest --testmon"')
return

ctx.run(f"poetry run {tox.pytest_command}")

if coverage:
Expand Down Expand Up @@ -196,17 +206,15 @@ def lint(ctx, recreate=False):
raise Exit("pylint failed", 1)


@task(help={"venv": "Remove the Poetry virtualenv"})
@task(help={"venv": "Remove the Poetry virtualenv and the tox dir"})
def clean(ctx, venv=False):
"""Clean build output and temp files."""
ctx.run("find . -type f -name '*.py[co]' -print -delete")
ctx.run("find . -type d -name '__pycache__' -print -delete")
ctx.run(
"find . -type d \\( -name '*.egg-info' -or -name 'pip-wheel-metadata' -or -name 'dist' \\) -print0 | "
"xargs -0 rm -rvf"
)
ctx.run(f"rm -rvf .cache .mypy_cache {DOCS_BUILD_PATH} src/*.egg-info .pytest_cache .coverage htmlcov .tox")
ctx.run("find . -type d \\( -name '*.egg-info' -or -name 'pip-wheel-metadata' -or -name 'dist' \\) -print -delete")
ctx.run(f"rm -rf .cache .mypy_cache {DOCS_BUILD_PATH} src/*.egg-info .pytest_cache .coverage htmlcov .testmondata")
if venv:
ctx.run("rm -rf .tox")
ctx.run("poetry env remove python3.6", warn=True)


Expand Down

0 comments on commit 4faab57

Please sign in to comment.