Skip to content

Commit 234923c

Browse files
committed
Run the functests in reverse in dev
For speed h doesn't clear the DB between functests, see: #6845 As a defence against tests becoming dependent on data left in the DB by the tests that run before them, we ran the functests in reverse order on CI (but in normal order in dev). This was achieved by adding the `pytest-reverse` dependency and adding `--reverse` to the `pytest` command in CI. See: #7013 The `--reverse` was later accidentally removed by #8264 The cookiecutter has since been applied to h and the cookiecutter doesn't do the `--reverse` either. The cookiecutter's `ci.yml` doesn't provide a way for an individual project to add a command line argument to the `pytest` command for the functests. One solution would be to add such an option to the cookiecutter, but it's awkward and I don't like adding too many options to the cookiecutter. Another solution would be to add the `pytest-reverse` dependency and `--reverse` argument to the cookiecutter and have it be applied to all projects. This could be a good option, but [pytest-reverse](https://github.com/adamchainz/pytest-reverse) is a third-party pytest plugin not an official one, and not very popular, so perhaps we don't want to depend on it in every repo. Also, all our other projects reset the DB before each unittest of functest so they have no need for `pytest-reverse`. If we ever fix h to reset the DB before each functest we'll remove the `pytest-reverse` dependency from h as well. This commit goes for a third option: run the tests in reverse _in development_ rather than on CI, which we can easily do with the cookiecutter's existing functionality for per-project customisation of the `PYTEST_ADDOPTS` option. wip
1 parent c948dcf commit 234923c

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

.cookiecutter/includes/tox/setenv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ dev: REPLICA_DATABASE_URL = {env:DATABASE_URL:postgresql://postgres@localhost/po
1313
dev: MAILCHIMP_USER_ACTIONS_SUBACCOUNT = {env:MAILCHIMP_USER_ACTIONS_SUBACCOUNT:devdata}
1414
tests: ELASTICSEARCH_INDEX = {env:ELASTICSEARCH_INDEX:hypothesis-tests}
1515
functests: ELASTICSEARCH_INDEX = {env:ELASTICSEARCH_INDEX:hypothesis-functests}
16+
functests: PYTEST_ADDOPTS = {env:PYTEST_ADDOPTS:{tty::--reverse}}
1617
{tests,functests}: AUTHORITY = {env:AUTHORITY:example.com}

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[tool.pytest.ini_options]
2-
addopts = "-q"
32
filterwarnings = [
43
"error", # Fail the tests if there are any warnings.
54
"ignore:^find_module\\(\\) is deprecated and slated for removal in Python 3.12; use find_spec\\(\\) instead$:DeprecationWarning:importlib",

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ setenv =
3737
dev: MAILCHIMP_USER_ACTIONS_SUBACCOUNT = {env:MAILCHIMP_USER_ACTIONS_SUBACCOUNT:devdata}
3838
tests: ELASTICSEARCH_INDEX = {env:ELASTICSEARCH_INDEX:hypothesis-tests}
3939
functests: ELASTICSEARCH_INDEX = {env:ELASTICSEARCH_INDEX:hypothesis-functests}
40+
functests: PYTEST_ADDOPTS = {env:PYTEST_ADDOPTS:{tty::--reverse}}
4041
{tests,functests}: AUTHORITY = {env:AUTHORITY:example.com}
4142
passenv =
4243
HOME
@@ -85,7 +86,7 @@ commands =
8586
lint: {posargs:ruff check h tests bin}
8687
{tests,functests}: python3 -m h.scripts.init_db --delete --create
8788
tests: python -m pytest --cov --cov-report= --cov-fail-under=0 {posargs:--numprocesses logical --dist loadgroup tests/unit/}
88-
functests: python -m pytest --failed-first --new-first --no-header --quiet {posargs:tests/functional/}
89+
functests: python -m pytest {posargs:tests/functional/}
8990
coverage: coverage combine
9091
coverage: coverage report
9192
typecheck: mypy h

0 commit comments

Comments
 (0)