-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: add --db-backend pytest option (#6625)
Instead of choosing the database backend (SQLite or Postgres) implicitly via markers, we add an explicit `--db-backend ` option to pytest. ``` --db-backend=DB_BACKEND Database backend to be used for tests ('sqlite', 'psql') ``` - The default backend was changed from `psql` to `sqlite` to make local testing easier. - The tests running in CI are still using Postgres in most places. - The only change in CI should be switching the rabbitmq tests and release tests to use sqlite. Error if the user provides an invalid option ``` ❯ pytest --db-backend=invalid ERROR: Invalid --db-backend option 'invalid' Must be one of: ('sqlite', 'psql') ``` To clarify, the existing presto marker works as before.
- Loading branch information
1 parent
1c5f109
commit a863d1e
Showing
11 changed files
with
141 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""Tests markers that have custom in conftest.py""" | ||
|
||
import pytest | ||
|
||
|
||
def test_presto_auto_mark(request): | ||
"""Test that the presto marker is added automatically""" | ||
own_markers = [marker.name for marker in request.node.own_markers] | ||
assert len(own_markers) == 1 | ||
assert own_markers[0] == 'presto' | ||
|
||
|
||
@pytest.mark.sphinx | ||
def test_presto_mark_and_another_mark(request): | ||
"""Test that presto marker is added even if there is an existing marker (except requires_rmq|psql)""" | ||
own_markers = [marker.name for marker in request.node.own_markers] | ||
|
||
assert len(own_markers) == 2 | ||
assert 'presto' in own_markers | ||
assert 'sphinx' in own_markers | ||
|
||
|
||
@pytest.mark.requires_rmq | ||
def test_no_presto_mark_if_rmq(request): | ||
"""Test that presto marker is NOT added if the test is mark with "requires_rmq""" | ||
own_markers = [marker.name for marker in request.node.own_markers] | ||
|
||
assert len(own_markers) == 1 | ||
assert own_markers[0] == 'requires_rmq' | ||
|
||
|
||
@pytest.mark.requires_psql | ||
def test_no_presto_mark_if_psql(request): | ||
"""Test that presto marker is NOT added if the test is mark with "requires_psql""" | ||
own_markers = [marker.name for marker in request.node.own_markers] | ||
|
||
assert len(own_markers) == 1 | ||
assert own_markers[0] == 'requires_psql' | ||
|
||
|
||
@pytest.mark.nightly | ||
def test_no_presto_mark_if_nightly(request): | ||
"""Test that presto marker is NOT added if the test is mark with "requires_psql""" | ||
own_markers = [marker.name for marker in request.node.own_markers] | ||
|
||
assert len(own_markers) == 1 | ||
assert own_markers[0] == 'nightly' | ||
|
||
|
||
@pytest.mark.requires_psql | ||
def test_requires_psql_with_sqlite_impossible(pytestconfig): | ||
db_backend = pytestconfig.getoption('--db-backend') | ||
if db_backend.value == 'sqlite': | ||
pytest.fail('This test should not have been executed with SQLite backend!') | ||
|
||
|
||
def test_daemon_client_fixture_automarked(request, daemon_client): | ||
"""Test that any test using ``daemon_client`` fixture is | ||
automatically tagged with 'requires_rmq' mark | ||
""" | ||
own_markers = [marker.name for marker in request.node.own_markers] | ||
|
||
assert len(own_markers) == 1 | ||
assert own_markers[0] == 'requires_rmq' |