Skip to content

Commit

Permalink
feat: Allow the customization of the location at which the built in t…
Browse files Browse the repository at this point in the history
…ests are executed.
  • Loading branch information
DanCardin committed Jul 13, 2020
1 parent 7f873ec commit 255c95c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/pytest_alembic/plugin/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ def pytest_addoption(parser):
"List of built-in tests to exclude. Ignored if 'pytest_alembic_include' is specified."
f"Valid options include: {default_tests}",
)
parser.addini(
"pytest_alembic_tests_folder",
"The location under which the built-in tests will be bound. This defaults to 'tests/' "
"(the tests themselves then being executed from tests/pytest_alembic/*), the typical test "
"location. However this can be customized if pytest is, for example, invoked from a parent "
"directory like `pytest folder/tests`, or the tests are otherwise located at a different "
"location, relative to `pytest`s invocation.",
default="tests",
)

group = parser.getgroup("collect")
group.addoption(
Expand Down
5 changes: 3 additions & 2 deletions src/pytest_alembic/plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ def collect_tests(session, config):
all_tests = collect_all_tests()
test_names = enabled_test_names(set(all_tests), raw_included_tests, raw_excluded_tests)

tests_folder = config.getini("pytest_alembic_tests_folder")

result = []
for test_name in sorted(test_names):
test = all_tests[test_name]

# XXX: "tests" should become an ini configurable option.
result.append(
PytestAlembicItem.from_parent(
session, name=f"tests::pytest_alembic::{test.__name__}", test_fn=test
session, name=f"{tests_folder}::pytest_alembic::{test.__name__}", test_fn=test
)
)

Expand Down
21 changes: 20 additions & 1 deletion tests/plugin/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from pytest_alembic.plugin.plugin import parse_raw_test_names, enabled_test_names

from pytest_alembic.plugin.plugin import enabled_test_names, parse_raw_test_names


def test_parse_raw_test_names_empty_skips():
Expand Down Expand Up @@ -84,3 +85,21 @@ def test_included_tests_start_with_tests(self, testdir):
for test in tests:
assert f"tests::pytest_alembic::{test}" in stdout
assert "4 passed" in stdout

def test_alternative_test_folter(self, testdir):
testdir.copy_example("test_no_data")
testdir.makefile(".ini", pytest="[pytest]\npytest_alembic_tests_folder=foo\n")
result = testdir.runpytest("--test-alembic", "-vv")
stdout = result.stdout.str()
print(stdout)

assert result.ret == 0
tests = [
"test_model_definitions_match_ddl",
"test_single_head_revision",
"test_up_down_consistency",
"test_upgrade",
]
for test in tests:
assert f"foo::pytest_alembic::{test}" in stdout
assert "4 passed" in stdout

0 comments on commit 255c95c

Please sign in to comment.