Skip to content

Rename test databases when running parallel Tox #680

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

Merged
merged 1 commit into from
Aug 26, 2019

Conversation

adamantike
Copy link
Contributor

@adamantike adamantike commented Dec 17, 2018

When tests are executed using Tox in parallel, modify the test database
names, to avoid name collisions between processes.

This change renames the existing
django_db_modify_db_settings_xdist_suffix fixture, to a generic
django_db_modify_db_settings_parallel_suffix one, in case more
scenarios/tools have to be considered in the future.

It also handles projects where both pytest-xdist and parallel tox
are being using, generating database names like
test_default_py37-django21_gw0.

This change is based on tox new parallel mode [0].

Resolves #678.

[0] tox-dev/tox#1102

@codecov-io
Copy link

codecov-io commented Dec 17, 2018

Codecov Report

Merging #680 into master will decrease coverage by 0.09%.
The diff coverage is 71.42%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #680     +/-   ##
=========================================
- Coverage   94.43%   94.34%   -0.1%     
=========================================
  Files          33       33             
  Lines        1852     1857      +5     
  Branches      158      160      +2     
=========================================
+ Hits         1749     1752      +3     
- Misses         78       79      +1     
- Partials       25       26      +1
Flag Coverage Δ
#dj110 86.16% <42.85%> (-0.18%) ⬇️
#dj111 88.63% <71.42%> (-0.08%) ⬇️
#dj18 87.12% <42.85%> (-0.19%) ⬇️
#dj19 85.94% <42.85%> (-0.18%) ⬇️
#dj20 86.42% <42.85%> (-0.18%) ⬇️
#dj21 82.6% <57.14%> (-0.07%) ⬇️
#djmaster 82.6% <57.14%> (-0.07%) ⬇️
#mysql_innodb 86.64% <42.85%> (-0.18%) ⬇️
#mysql_myisam 86.48% <42.85%> (-0.18%) ⬇️
#postgres 89.76% <42.85%> (-0.19%) ⬇️
#py27 91.43% <42.85%> (-0.2%) ⬇️
#py34 85.94% <42.85%> (-0.18%) ⬇️
#py35 86.16% <42.85%> (-0.18%) ⬇️
#py36 87.45% <71.42%> (-0.08%) ⬇️
#py37 82.6% <57.14%> (-0.07%) ⬇️
#sqlite 88.58% <71.42%> (-0.08%) ⬇️
#sqlite_file 85.94% <42.85%> (-0.18%) ⬇️
Impacted Files Coverage Δ
pytest_django/plugin.py 93.62% <100%> (ø) ⬆️
pytest_django/fixtures.py 96.33% <66.66%> (-0.98%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 82de481...8f73185. Read the comment docs.

@codecov-io
Copy link

codecov-io commented Dec 17, 2018

Codecov Report

Merging #680 into master will decrease coverage by 0.27%.
The diff coverage is 84.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #680      +/-   ##
==========================================
- Coverage   98.06%   97.78%   -0.28%     
==========================================
  Files          32       32              
  Lines        1862     1899      +37     
  Branches      147      150       +3     
==========================================
+ Hits         1826     1857      +31     
- Misses         24       27       +3     
- Partials       12       15       +3
Impacted Files Coverage Δ
tests/test_db_setup.py 100% <100%> (ø) ⬆️
pytest_django/plugin.py 94.04% <100%> (+0.03%) ⬆️
pytest_django/fixtures.py 93.71% <70.37%> (-2.7%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c1bdb8d...3da7437. Read the comment docs.

@adamantike adamantike force-pushed the tox-parallel-support branch 2 times, most recently from 7282d75 to a6f355b Compare January 14, 2019 18:08
@adamantike adamantike changed the title [WIP] Rename test databases when running parallel Tox Rename test databases when running parallel Tox Jan 14, 2019
adamantike added a commit to adamantike/tox that referenced this pull request Jan 14, 2019
To allow other libraries, or projects, to know if Tox is running in
parallel mode, add the `TOX_PARALLEL_ENV` environment variable to the
list of injected variables.

Particularly, this is useful for `pytest-django` to know if Tox is
running in parallel mode, to rename test databases [0].

[0] pytest-dev/pytest-django#680
adamantike added a commit to adamantike/tox that referenced this pull request Jan 14, 2019
To allow other libraries, or projects, to know if Tox is running in
parallel mode, add the `TOX_PARALLEL_ENV` environment variable to the
list of injected variables.

Particularly, this is useful for `pytest-django` to know if Tox is
running in parallel mode, to rename test databases [0].

[0] pytest-dev/pytest-django#680
@adamantike adamantike force-pushed the tox-parallel-support branch from a6f355b to 7e02ddf Compare January 14, 2019 21:18
adamantike added a commit to adamantike/tox that referenced this pull request Jan 14, 2019
To allow other libraries, or projects, to know if Tox is running in
parallel mode, add the `TOX_PARALLEL_ENV` environment variable to the
list of injected variables.

Particularly, this is useful for `pytest-django` to know if Tox is
running in parallel mode, to rename test databases [0].

[0] pytest-dev/pytest-django#680
@adamantike
Copy link
Contributor Author

@blueyed updated to avoid removing the previous fixture, and avoided code duplication between the two new fixtures.

This now depends on tox-dev/tox#1139 being merged, for the TOX_PARALLEL_ENV to be present, and we can identify a parallel run.

adamantike added a commit to adamantike/tox that referenced this pull request Jan 15, 2019
To allow other libraries, or projects, to know if Tox is running in
parallel mode, add the `TOX_PARALLEL_ENV` environment variable to the
list of injected variables.

Particularly, this is useful for `pytest-django` to know if Tox is
running in parallel mode, to rename test databases [0].

[0] pytest-dev/pytest-django#680
adamantike added a commit to adamantike/tox that referenced this pull request Jan 15, 2019
To allow other libraries, or projects, to know if Tox is running in
parallel mode, add the `TOX_PARALLEL_ENV` environment variable to the
list of injected variables.

Particularly, this is useful for `pytest-django` to know if Tox is
running in parallel mode, to rename test databases [0].

[0] pytest-dev/pytest-django#680
gaborbernat pushed a commit to tox-dev/tox that referenced this pull request Jan 15, 2019
* Inject TOX_PARALLEL_ENV environment variables

To allow other libraries, or projects, to know if Tox is running in
parallel mode, add the `TOX_PARALLEL_ENV` environment variable to the
list of injected variables.

Particularly, this is useful for `pytest-django` to know if Tox is
running in parallel mode, to rename test databases [0].

[0] pytest-dev/pytest-django#680

* Use strings (bytestrings in Python 2) in passenv whitelist
@blueyed
Copy link
Contributor

blueyed commented Jan 15, 2019

tox-dev/tox#1139 was merged for tox, so we can proceed here.
I would like to have this covered 100%.

@blueyed
Copy link
Contributor

blueyed commented Mar 9, 2019

Please rebase / fix coverage.

@adamantike adamantike force-pushed the tox-parallel-support branch 5 times, most recently from 7123ee3 to bbe5b8b Compare March 12, 2019 13:29
@adamantike adamantike force-pushed the tox-parallel-support branch 3 times, most recently from 5b73d1c to 0258e25 Compare July 25, 2019 21:08
When tests are executed using Tox in parallel, modify the test database
names, to avoid name collisions between processes.

This change renames the existing
`django_db_modify_db_settings_xdist_suffix` fixture, to a generic
`django_db_modify_db_settings_parallel_suffix` one, in case more
scenarios/tools have to be considered in the future.

It also handles projects where both `pytest-xdist` and parallel `tox`
are being using, generating database names like
`test_default_py37-django21_gw0`.

Resolves pytest-dev#678.
@adamantike adamantike force-pushed the tox-parallel-support branch from 0258e25 to 3da7437 Compare July 25, 2019 21:18
@adamantike
Copy link
Contributor Author

@blueyed, rebased and improved coverage! There's only one line without coverage at the moment, which requires the database engine not to be django.db.backends.sqlite3 (and is also uncovered in master). Trying to use a different engine requires specific test classes for MySQL or Postgres in test_db_setup.py, something that hasn't been done yet.

Let me know how you'd like to proceed :)

@adamantike
Copy link
Contributor Author

@blueyed bump!

@blueyed blueyed merged commit d2973e2 into pytest-dev:master Aug 26, 2019
@blueyed
Copy link
Contributor

blueyed commented Aug 26, 2019

@adamantike
Thanks!
(and sorry for the slow response)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Correctly support DB access in parallel Tox testing
3 participants