Skip to content

Commit 4d7ae63

Browse files
committed
Including bdd and updates
1 parent 94f140b commit 4d7ae63

File tree

6 files changed

+134
-12
lines changed

6 files changed

+134
-12
lines changed

{{cookiecutter.project_slug}}/.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[flake8]
22
#ignore = E203, E266, E501, W503, T499, ANN101, ANN102, ANN002, ANN003, S101, SCS108
3-
ignore = E501
3+
ignore = E501,SCS109
44
max-line-length = 79
55
enable-extensions=G
66
#select = B,C,E,F,W,T4,T0,N8,DC,DAR,SCS

{{cookiecutter.project_slug}}/docs/mkdocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ theme:
1313

1414
nav:
1515
- index.md
16-
- API: mkapi/api/python_base_package
16+
- API: mkapi/api/{{cookiecutter.package_name}}
1717
- Tests: mkapi/tests/tests
1818

{{cookiecutter.project_slug}}/poetry.lock

Lines changed: 73 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

{{cookiecutter.project_slug}}/pyproject.toml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ flake8-annotations = "^2.8.0"
4343
flake8-black = "^0.3.2"
4444
flake8-mypy = "^17.8.0"
4545
flake8-simplify = "^0.19.3"
46+
flake8-isort = "^5.0.0"
4647
pytest = "7.1.1"
4748
pytest-html = "^3.1.1"
4849
pytest-sugar = "^0.9.6"
4950
pytest-flake8 = "^1.1.1"
5051
pytest-reverse = "^1.5.0"
5152
pytest-cov = "^3.0.0"
53+
pytest-bdd = "^6.1.1"
54+
55+
[tool.poetry.scripts]
56+
-x = "poethepoet:main"
5257

5358
[build-system]
5459
requires = ["poetry-core>=1.0.0"]
@@ -109,6 +114,7 @@ testpaths = [
109114
python_files = ["*_test.py"]
110115
python_functions = ["test_*"]
111116
render_collapsed = true
117+
bdd_features_base_dir = "features"
112118

113119
[tool.coverage.report]
114120
exclude_lines = [
@@ -138,11 +144,12 @@ pretty = true
138144
[tool.poe.tasks]
139145
install = "poetry install --only main"
140146
install-dev = "poetry install"
141-
run = "poetry run python -m {{cookiecutter.package_name}}.{{cookiecutter.module_name}}"
142-
test = "poetry run pytest"
143-
pre-commit = "poetry run pre-commit run --all-files"
144-
lint = "poetry run flake8"
145-
doc = "poetry run mkdocs serve --use-directory-urls -f docs/mkdocs.yaml"
147+
run = "python -m {{cookiecutter.package_name}}.{{cookiecutter.module_name}}"
148+
test = "pytest"
149+
pre-commit = "pre-commit run --all-files"
150+
lint = "flake8"
151+
doc = "mkdocs serve --use-directory-urls -f docs/mkdocs.yaml"
152+
doc-html = "mkdocs build --use-directory-urls -f docs/mkdocs.yaml"
146153

147154
[tool.poe.tasks.docker-build]
148155
cmd = """
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""Init file for test module."""
1+
"""Tests module."""
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Configuration file for pytest.
2+
3+
This module will inject configuration scripts before running tests.
4+
"""
5+
from pytest_bdd import feature
6+
from pytest_bdd.scenario import get_features_base_dir
7+
from pytest_bdd.utils import get_caller_module_path
8+
from pathlib import Path
9+
import pytest
10+
11+
12+
def pytest_configure(config: pytest.Config) -> None:
13+
"""Configure tests tp include new features.
14+
15+
Args:
16+
config (Config): Configuration provided by pytest.
17+
18+
"""
19+
conftest_dir = Path(__file__).parent
20+
caller_module_path = get_caller_module_path()
21+
features_base_dir = get_features_base_dir(caller_module_path)
22+
features = feature.get_features([features_base_dir])
23+
24+
for feat in features:
25+
26+
feature_dir = Path(feat.filename).parent
27+
file_dir = (
28+
conftest_dir / "steps" / feature_dir.relative_to(features_base_dir)
29+
)
30+
file_name = Path(feat.filename).stem + "_test.py"
31+
file_path = file_dir / file_name
32+
feature_rel_path = Path(feat.filename).relative_to(features_base_dir)
33+
txt = (
34+
'"""Feature steps implementation.\n'
35+
"\n"
36+
f'Source file: {feature_rel_path}\n"""\n'
37+
"from pytest_bdd import scenarios\n"
38+
"\n"
39+
f"""scenarios("{feature_rel_path}")"""
40+
)
41+
42+
file_dir.mkdir(parents=True, exist_ok=True)
43+
44+
if not file_path.exists():
45+
with open(file_path, "w") as f:
46+
f.write(txt)

0 commit comments

Comments
 (0)