mirror of
https://github.com/YunoHost-Apps/django_example_ynh.git
synced 2024-09-03 18:26:21 +02:00
Replace "run_pytest.py" with "tests/conftest.py"
This commit is contained in:
parent
0a5775fbc3
commit
aacfbabc2b
6 changed files with 49 additions and 35 deletions
2
Makefile
2
Makefile
|
@ -45,7 +45,7 @@ tox: check-poetry ## Run pytest via tox with all environments
|
|||
poetry run tox
|
||||
|
||||
pytest: install ## Run pytest
|
||||
poetry run python3 ./run_pytest.py
|
||||
poetry run pytest
|
||||
|
||||
local-test: install ## Run local_test.py to run the project locally
|
||||
poetry run python3 ./local_test.py
|
||||
|
|
|
@ -16,9 +16,9 @@ django-ipware==4.0.2; python_version >= "3.7" and python_full_version < "3.0.0"
|
|||
django-redis==5.2.0; python_version >= "3.7" and python_full_version < "4.0.0" \
|
||||
--hash=sha256:8a99e5582c79f894168f5865c52bd921213253b7fd64d16733ae4591564465de \
|
||||
--hash=sha256:1d037dc02b11ad7aa11f655d26dac3fb1af32630f61ef4428860a2e29ff92026
|
||||
django-yunohost-integration==0.2.5; python_version >= "3.7" and python_full_version < "4.0.0" \
|
||||
--hash=sha256:b5f9beea73515ffb8816644cde766cdd0170ce75441ceb9ac11e185f40470186 \
|
||||
--hash=sha256:2cade1dc6d77974139624883475dfe360fe04a86335b635f1fac2401acae56d8
|
||||
django-yunohost-integration==0.3.0; python_version >= "3.7" and python_full_version < "4.0.0" \
|
||||
--hash=sha256:f7f8e9d55c50231bb32d3809b240d6ac718aadac1a1f471284baa1bfa6e98dff \
|
||||
--hash=sha256:d0e9cc91d241075613cb54b5da0879ad9b8ad3d22b84130cd7a331025650406e
|
||||
django==3.2.15; python_version >= "3.7" and python_full_version < "4.0.0" \
|
||||
--hash=sha256:115baf5049d5cf4163e43492cdc7139c306ed6d451e7d3571fe9612903903713 \
|
||||
--hash=sha256:f71934b1a822f14a86c9ac9634053689279cd04ae69cb6ade4a59471b886582b
|
||||
|
|
8
poetry.lock
generated
8
poetry.lock
generated
|
@ -253,7 +253,7 @@ hiredis = ["redis[hiredis] (>=3,!=4.0.0,!=4.0.1)"]
|
|||
|
||||
[[package]]
|
||||
name = "django-yunohost-integration"
|
||||
version = "0.2.5"
|
||||
version = "0.3.0"
|
||||
description = "Glue code to package django projects as yunohost apps."
|
||||
category = "main"
|
||||
optional = false
|
||||
|
@ -718,7 +718,7 @@ docs = ["jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "jaraco.packaging (>=9)
|
|||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = ">=3.7,<4.0.0" # TODO: Update to >=3.8 after YunoHost updates to Bullseye
|
||||
content-hash = "477d486f59495a9e626d97f184b0c05db2642a62627f98758cdb90221cea1ebf"
|
||||
content-hash = "e1bf9af0ee47f901c1febf1757dafc4f2c736b9df0d36d33cbd44883ee06c556"
|
||||
|
||||
[metadata.files]
|
||||
asgiref = [
|
||||
|
@ -861,8 +861,8 @@ django-redis = [
|
|||
{file = "django_redis-5.2.0-py3-none-any.whl", hash = "sha256:1d037dc02b11ad7aa11f655d26dac3fb1af32630f61ef4428860a2e29ff92026"},
|
||||
]
|
||||
django-yunohost-integration = [
|
||||
{file = "django_yunohost_integration-0.2.5-py3-none-any.whl", hash = "sha256:b5f9beea73515ffb8816644cde766cdd0170ce75441ceb9ac11e185f40470186"},
|
||||
{file = "django_yunohost_integration-0.2.5.tar.gz", hash = "sha256:2cade1dc6d77974139624883475dfe360fe04a86335b635f1fac2401acae56d8"},
|
||||
{file = "django_yunohost_integration-0.3.0-py3-none-any.whl", hash = "sha256:f7f8e9d55c50231bb32d3809b240d6ac718aadac1a1f471284baa1bfa6e98dff"},
|
||||
{file = "django_yunohost_integration-0.3.0.tar.gz", hash = "sha256:d0e9cc91d241075613cb54b5da0879ad9b8ad3d22b84130cd7a331025650406e"},
|
||||
]
|
||||
docopt = [
|
||||
{file = "docopt-0.6.2.tar.gz", hash = "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491"},
|
||||
|
|
|
@ -11,7 +11,7 @@ homepage = "https://github.com/YunoHost-Apps/django_example_ynh"
|
|||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.7,<4.0.0" # TODO: Update to >=3.8 after YunoHost updates to Bullseye
|
||||
django_yunohost_integration = {version = "*", extras = ["ynh"]}
|
||||
django_yunohost_integration = {version = ">=0.3.0", extras = ["ynh"]}
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
bx_py_utils = "*" # https://github.com/boxine/bx_py_utils
|
||||
|
@ -63,7 +63,7 @@ lines_after_imports=2
|
|||
[tool.pytest.ini_options]
|
||||
# https://docs.pytest.org/en/latest/customize.html#pyproject-toml
|
||||
minversion = "6.0"
|
||||
norecursedirs = ".* .git __pycache__ conf coverage* dist htmlcov"
|
||||
norecursedirs = ".* .git __pycache__ conf local_test coverage* dist htmlcov"
|
||||
# sometimes helpfull "addopts" arguments:
|
||||
# -vv
|
||||
# --verbose
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
"""
|
||||
Run pytest against local test creation
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
try:
|
||||
from django_yunohost_integration.pytest_helper import run_pytest
|
||||
except ImportError as err:
|
||||
raise ImportError('Did you forget to activate a virtual environment?') from err
|
||||
|
||||
|
||||
BASE_PATH = Path(__file__).parent
|
||||
|
||||
|
||||
def main():
|
||||
run_pytest(
|
||||
django_settings_path=BASE_PATH / 'conf' / 'settings.py',
|
||||
destination=BASE_PATH / 'local_test',
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
39
tests/conftest.py
Normal file
39
tests/conftest.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
"""
|
||||
Special pytest init:
|
||||
|
||||
- Build a "local_test" YunoHost installation
|
||||
- init Django with this local test installation
|
||||
|
||||
So the pytests will run against this local test installation
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import django
|
||||
|
||||
from django_yunohost_integration.local_test import create_local_test
|
||||
|
||||
|
||||
BASE_PATH = Path(__file__).parent.parent
|
||||
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
|
||||
|
||||
|
||||
def pytest_configure():
|
||||
print('Compile YunoHost files...')
|
||||
final_path = create_local_test(
|
||||
django_settings_path=BASE_PATH / 'conf' / 'settings.py',
|
||||
destination=BASE_PATH / 'local_test',
|
||||
runserver=False,
|
||||
extra_replacements={},
|
||||
)
|
||||
print('Local test files created here:')
|
||||
print(f'"{final_path}"')
|
||||
|
||||
os.chdir(final_path)
|
||||
final_home_str = str(final_path)
|
||||
if final_home_str not in sys.path:
|
||||
sys.path.insert(0, final_home_str)
|
||||
|
||||
django.setup()
|
Loading…
Reference in a new issue