Skip to content
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

Add a functional test runner #805

Merged
merged 3 commits into from Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion .coveragerc
Expand Up @@ -2,6 +2,8 @@
source = dynaconf

[report]
show_missing = true
fail_under = 100
omit =
*/python?.?/*
*/site-packages/nose/*
Expand All @@ -11,7 +13,7 @@ omit =
dynaconf/loaders/redis_loader.py
dynaconf/loaders/vault_loader.py
dynaconf/loaders/__init__.py
dynaconf/example/*
dynaconf/tests_functional/*
dynaconf/vendor/*
dynaconf/vendor_src/*
dynaconf/contrib/django_dynaconf/*
33 changes: 1 addition & 32 deletions .github/workflows/main.yml
Expand Up @@ -181,38 +181,7 @@ jobs:
- name: Install project
run: pip install --use-deprecated=legacy-resolver .[test]
- name: run tests
run: |
pushd example\common & cd & python program.py & popd
pushd example\common-encoding & cd & python program.py & popd
pushd example\ & cd & python full_example.py & popd
pushd example\ & cd & python compat.py & popd
pushd example\app & cd & python app.py & popd
pushd example\app_with_dotenv & cd & python app.py & popd
pushd example\merge_enabled & cd & python app.py & popd
pushd example\new_merge & cd & python app.py & popd
pushd example\dynaconf_merge & cd & python app.py & popd
pushd example\multiple_sources & cd & python app.py & popd
pushd example\multiple_folders & cd & python app.py & popd
pushd example\toml_example\ & cd & python app.py & popd
pushd example\yaml_example\settings_file\ & cd & python app.py & popd
pushd example\yaml_example\yaml_as_extra_config\ & cd & python app.py & popd
pushd example\flask_with_dotenv & cd & flask routes & popd
pushd example\flask_with_toml & cd & flask routes & popd
pushd example\flask_with_yaml & cd & flask routes & popd
pushd example\flask_with_json & cd & flask routes & popd
pushd example\flask_with_commentjson & cd & flask routes & popd
pushd example\flask_with_ini & cd & flask routes & popd
pushd example\validators\with_python\ & cd & python app.py & popd
pushd example\validators\with_toml\ & cd & dynaconf validate & popd
pushd example\toml_with_secrets\ & cd & python program.py & popd
pushd example\envs & cd & python app.py & popd
pushd example\custom_loader & cd & python app.py & popd
pushd example\get_fresh & cd & python app.py & popd
pushd example\includes & cd & python app.py & popd
pushd example\jenkins_secrets_file & cd & python app.py & popd
pushd example\specific_settings_files & cd & python app.py & popd
pushd example\django_example\ & cd & python manage.py test polls -v 2 & popd
pushd example\django_example\ & cd & django-admin test polls -v 2 & popd
run: python tests_functional/runtests.py

redis:
needs: functional_tests_linux_mac
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Expand Up @@ -77,8 +77,8 @@ junit/


# django example static files
example/django_example/admin/
example/django_example/debug_toolbar/
tests_functional/django_example/admin/
tests_functional/django_example/debug_toolbar/


# Vendor_src exists only during build process
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Expand Up @@ -14,7 +14,7 @@ This Diagram can help you understand visually what happens on Dynaconf: https://
2. Activate a python3.6+ virtualenv
3. Code
2. Update the `docs/guides/` related to your changes.
3. Update `example/` (editing or adding a new one related to your changes)
3. Update `tests_functional/` (editing or adding a new one related to your changes)
4. Ensure tests are passing (see below `make all`)
1. This project uses `pre-commit` and `Black` for code styling and adequacy tests.
5. Commit, Push and make a Pull Request!
Expand Down Expand Up @@ -47,8 +47,8 @@ git fetch upstream; git rebase upstream/master
# Fix any conflicts if any.

# Update docs/guides/ if needed
# Edit example/ if needed
# Create a new app in example/{your_example} and add it to Makefile.
# Edit tests_functional/ if needed
# Create a new app in tests_functional/{your_example} and add it to Makefile.

# Then ensure everything is ok
make all
Expand Down
156 changes: 7 additions & 149 deletions Makefile
Expand Up @@ -6,163 +6,20 @@ help:

all: clean install run-pre-commit test test_examples coverage-report

test_examples:
@echo '############### Chdir to example directory ###############'
cd example/common;pwd;python program.py
cd example/common-encoding;pwd;python program.py
cd example/simple_ini_example;pwd;TEFLO_LOG_LEVEL=debug python app.py
cd example/;pwd;python full_example.py
cd example/;pwd;python compat.py
cd example/app;pwd;python app.py
cd example/apply_default_on_none;pwd;python app.py
cd example/dunder;pwd;python app.py
cd example/format;pwd;python app.py
cd example/app_with_dotenv;pwd;python app.py
cd example/dotenv_not_loaded_by_default;pwd;python app.py
cd example/dotenv_loaded_if_enabled;pwd;python app.py
cd example/merge_enabled;pwd;python app.py
cd example/new_merge;pwd;python app.py
cd example/overriding;pwd;python app.py
cd example/dynaconf_merge;pwd;python app.py
cd example/multiple_sources;pwd;python app.py
cd example/multiple_folders;pwd;python app.py
cd example/toml_example/;pwd;python app.py
cd example/yaml_example/settings_file/;pwd;python app.py
cd example/yaml_example/yaml_as_extra_config/;pwd;python app.py
cd example/flask_with_dotenv;pwd;flask routes | grep -c flask_with_dotenv || exit 1
cd example/flask_with_toml;pwd;flask routes | grep -c flask_with_toml || exit 1
cd example/flask_with_yaml;pwd;flask routes | grep -c flask_with_yaml || exit 1
cd example/flask_with_json;pwd;flask routes | grep -c flask_with_json || exit 1
cd example/flask_with_commentjson;pwd;flask routes | grep -c flask_with_commentjson || exit 1
cd example/flask_with_ini;pwd;flask routes | grep -c flask_with_ini || exit 1
cd example/pytest_example/app;pwd;python app.py
cd example/pytest_example/app;pwd;pytest tests/
cd example/pytest_example/flask;pwd;pytest tests
cd example/python_loader;pwd;python app.py
cd example/python_loader_with_hooks;pwd;python app.py
cd example/module_impersonation;pwd;python main.py
cd example/validators/with_python/;pwd;python app.py
cd example/validators/with_toml/;pwd;PYTHONPATH=. dynaconf -i config.settings validate
cd example/toml_with_secrets/;pwd;python program.py
cd example/envs;pwd;python app.py
cd example/envless_mode;pwd;python app.py
cd example/lower_read;pwd;python app.py
cd example/custom_loader;pwd;python app.py
cd example/get_fresh;pwd;python app.py
cd example/includes;pwd;python app.py
cd example/jenkins_secrets_file;pwd;python app.py
cd example/specific_settings_files;pwd;python app.py
cd example/django_example/;pwd;python manage.py test polls -v 2
cd example/django_pytest/;pwd;pip install pytest-django;DJANGO_SETTINGS_MODULE=project.settings DJANGO_ENVIRONMENT=default pytest;pip uninstall -y pytest-django
cd example/django_example_compat/;pwd;python manage.py test polls -v 2
cd example/django_example/;pwd;PYTHONPATH=. DJANGO_SETTINGS_MODULE=foo.settings django-admin test polls -v 2
cd example/project_root/;pwd;rm -rf /tmp/dynaconf_project_root_test/settings.py;mkdir -p /tmp/dynaconf_project_root_test/;echo "MESSAGE = 'Hello from tmp'" > /tmp/dynaconf_project_root_test/settings.py;python app.py;rm -rf /tmp/dynaconf_project_root_test/
cd example/settings_file/;pwd;rm -rf /tmp/settings_file_test/settings.py;mkdir -p /tmp/settings_file_test/;echo "MESSAGE = 'Hello from tmp'" > /tmp/settings_file_test/settings.py;python app.py;rm -rf /tmp/settings_file_test/
cd example/configure/;pwd;rm -rf /tmp/configure_test/settings.py;mkdir -p /tmp/configure_test/;echo "MESSAGE = 'Hello from tmp'" > /tmp/configure_test/settings.py;python app.py;rm -rf /tmp/configure_test/
cd example/-m_case/;pwd;python -m module
cd example/custom_cast_token;pwd;python app.py

@echo '############### Calling from outer folder ###############'
python example/common/program.py
python example/common-encoding/program.py
python example/full_example.py
python example/compat.py
python example/app/app.py
python example/app_with_dotenv/app.py
python example/merge_enabled/app.py
python example/dynaconf_merge/app.py
python example/multiple_sources/app.py
python example/multiple_folders/app.py
python example/toml_example/app.py
python example/yaml_example/settings_file/app.py
python example/yaml_example/yaml_as_extra_config/app.py
python example/validators/with_python/app.py
python example/toml_with_secrets/program.py
python example/envs/app.py
python example/custom_loader/app.py
python example/get_fresh/app.py
python example/includes/app.py
python example/jenkins_secrets_file/app.py
python example/specific_settings_files/app.py
python example/django_example/manage.py test polls -v 2
PYTHONPATH=example/django_example DJANGO_SETTINGS_MODULE=foo.settings python example/django_example/standalone_script.py
PYTHONPATH=example/issues/449_django_lazy_path DJANGO_SETTINGS_MODULE=foo.settings python example/django_example/standalone_script.py
PYTHONPATH=example/django_example_compat DJANGO_SETTINGS_MODULE=foo.settings python example/django_example_compat/standalone_script.py
python example/envvar_prefix/app.py

@echo '############### Django Admin From root folder ###############'
PYTHONPATH=./example/django_example/ DJANGO_SETTINGS_MODULE=foo.settings django-admin test polls -v 2
PYTHONPATH=./example/issues/449_django_lazy_path/ DJANGO_SETTINGS_MODULE=foo.settings django-admin test polls -v 2
PYTHONPATH=./example/django_example_compat/ DJANGO_SETTINGS_MODULE=foo.settings django-admin test polls -v 2

@echo '############ Issues ##################'
cd example/issues/160_path_traversal_fixed;pwd;./test.sh
cd example/issues/166_renamed_global_env;pwd;python app.py
cd example/issues/169_renamed_settings_module;pwd;python app.py
cd example/issues/182_multiple_locations;pwd;python app.py
cd example/issues/184_ipython;pwd;./test.sh
cd example/issues/194_flask_config;pwd;python app.py
cd example/issues/228_nested_toml_bool/python_app;pwd;python app.py
cd example/issues/228_nested_toml_bool/django_app;pwd;python manage.py test
cd example/issues/251_dotted_unexistent;pwd;python app.py
cd example/issues/253_set;pwd;python app.py
cd example/issues/266_envvar_from_env_override;pwd;python app.py
cd example/issues/288_null_values;pwd;python app.py
cd example/issues/306_merge_replace;pwd;python app.py
cd example/issues/359_variable_reference;pwd;python app.py
cd example/issues/384_dotted_set;pwd;python app.py
cd example/issues/392_evaluate_nested_structures;pwd;DYNACONF_INITIAL='@merge [1,2,3]' python app.py
cd example/issues/404_dup_validator_message;pwd;python app.py
cd example/issues/434_setenv;pwd;python app.py --config development dynaconf
cd example/issues/430_same_name;pwd;python app.py
cd example/issues/443_object_merge;pwd;python app.py
cd example/issues/445_casting;pwd;python app.py
cd example/issues/467_load_from_parent_folder/src;pwd;python app.py
cd example/issues/478_mispell_environments;pwd;python app.py
cd example/issues/482_layered_format;pwd;python app.py
cd example/issues/486_title_case_validation;pwd;python app.py
cd example/issues/494_using_pathlib;pwd;python app.py
cd example/issues/519_underscore_in_name;pwd;ATC_BLE__device_id=42 EXPECTED_VALUE=42 python app.py
cd example/issues/519_underscore_in_name;pwd;ATC_BLE__DEVICE_ID=42 EXPECTED_VALUE=42 python app.py
cd example/issues/685_disable_dotted_lookup;pwd;python app.py
cd example/issues/709_yaml_merge_with_env;pwd;python app.py
cd example/issues/718_dynaconf_dotted_lookup;pwd;python app.py
cd example/issues/720_load_dotenv;pwd;python src/app/app.py
cd example/issues/722_docs_example;pwd;python app.py
cd example/issues/729_use_default_when_setting_is_blank;pwd;python app.py
cd example/issues/741_envvars_ignored;pwd;sh recreate.sh
cd example/issues/705_flask_dynaconf_init;pwd;make test;make clean
cd example/issues/794_includes;pwd;python app.py
cd example/issues/799_negative_numbers;pwd;DYNACONF_NUM="-1" python app.py
test_functional:
./tests_functional/runtests.py

test_vault:
# @cd example/vault;pwd;python write.py
docker run --rm --name dynaconf_with_vault -d -e 'VAULT_DEV_ROOT_TOKEN_ID=myroot' -p 8200:8200 vault || true
@sleep 5
@cd example/vault;pwd;dynaconf -i dynaconf.settings write vault -s SECRET=vault_works_in_default -s FOO=foo_is_default
@cd example/vault;pwd;dynaconf -i dynaconf.settings write vault -e dev -s SECRET=vault_works_in_dev
@cd example/vault;pwd;dynaconf -i dynaconf.settings write vault -e prod -s SECRET=vault_works_in_prod
@sleep 2
@cd example/vault;pwd;python vault_example.py
docker stop dynaconf_with_vault || true
./tests_functional/test_vault.sh

test_redis:
# @cd example/redis_example;pwd;python write.py
docker run --rm --name dynaconf_with_redis -d -p 6379:6379 redis:alpine || true
@sleep 2
@cd example/redis_example;pwd;dynaconf -i dynaconf.settings write redis -s FOO=foo_is_default
@cd example/redis_example;pwd;dynaconf -i dynaconf.settings write redis -s SECRET=redis_works_in_default
@cd example/redis_example;pwd;dynaconf -i dynaconf.settings write redis -e development -s SECRET=redis_works_in_development
@cd example/redis_example;pwd;dynaconf -i dynaconf.settings write redis -e production -s SECRET=redis_works_in_production
@sleep 2
@cd example/redis_example;pwd;python redis_example.py
docker stop dynaconf_with_redis || true
./tests_functional/test_redis.sh

watch:
ls **/**.py | entr py.test -m "not integration" -s -vvv -l --tb=long --maxfail=1 tests/

watch_django:
ls {**/**.py,~/.virtualenvs/dynaconf/**/**.py,.venv/**/**.py} | PYTHON_PATH=. DJANGO_SETTINGS_MODULE=foo.settings entr example/django_example/manage.py test polls -v 2
ls {**/**.py,~/.virtualenvs/dynaconf/**/**.py,.venv/**/**.py} | PYTHON_PATH=. DJANGO_SETTINGS_MODULE=foo.settings entr tests_functional/django_example/manage.py test polls -v 2

watch_coverage:
ls {**/**.py,~/.virtualenvs/dynaconf/**/**.py} | entr -s "make test;coverage html"
Expand All @@ -176,7 +33,7 @@ test_integration:
coverage xml

coverage-report:
coverage report --fail-under=100
coverage report

mypy:
mypy dynaconf/ --exclude '^dynaconf/vendor*'
Expand All @@ -186,6 +43,7 @@ test: pep8 mypy test_only
citest:
py.test -v --cov-config .coveragerc --cov=dynaconf -l tests/ --junitxml=junit/test-results.xml
coverage xml
make coverage-report

ciinstall:
python -m pip install --upgrade pip
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced.md
Expand Up @@ -167,7 +167,7 @@ def load(
obj._loaded_files.append(sops_file)
```

See more [example/custom_loader](https://github.com/dynaconf/dynaconf/tree/master/example/custom_loader)
See more [tests_functional/custom_loader](https://github.com/dynaconf/dynaconf/tree/master/tests_functional/custom_loader)

## Module impersonation

Expand Down Expand Up @@ -413,7 +413,7 @@ Then your `program.py` will print `"On Testing"` red from `[testing]` environmen
For pytest it is common to create fixtures to provide pre-configured settings object or to configure the settings before
all the tests are collected.

Examples available on [https://github.com/dynaconf/dynaconf/tree/master/example/pytest_example](https://github.com/dynaconf/dynaconf/tree/master/example/pytest_example)
Examples available on [https://github.com/dynaconf/dynaconf/tree/master/tests_functional/pytest_example](https://github.com/dynaconf/dynaconf/tree/master/tests_functional/pytest_example)

With `pytest` fixtures it is recommended to use the `FORCE_ENV_FOR_DYNACONF` instead of just `ENV_FOR_DYNACONF` because it has precedence.

Expand Down
2 changes: 1 addition & 1 deletion docs/django.md
Expand Up @@ -32,7 +32,7 @@ $ dynaconf init --django yourapp/settings.py

Dynaconf will append its extension loading code to the bottom of your `yourapp/settings.py` file and will create `settings.toml` and `.secrets.toml` in the current folder (the same where `manage.py` is located).

> **TIP** Take a look at [example/django_example](https://github.com/dynaconf/dynaconf/tree/master/example/django_example)
> **TIP** Take a look at [tests_functional/django_example](https://github.com/dynaconf/dynaconf/tree/master/tests_functional/django_example)

## Using `DJANGO_` environment variables

Expand Down
14 changes: 13 additions & 1 deletion dynaconf/cli.py
@@ -1,7 +1,6 @@
from __future__ import annotations

import importlib
import io
import os
import pprint
import sys
Expand Down Expand Up @@ -264,6 +263,19 @@ def init(ctx, fileformat, path, env, _vars, _secrets, wg, y, django):
"""
click.echo("⚙️ Configuring your Dynaconf environment")
click.echo("-" * 42)
if "FLASK_APP" in os.environ: # pragma: no cover
click.echo(
"⚠️ Flask detected, you can't use `dynaconf init` "
"on a flask project, instead go to dynaconf.com/flask/ "
"for more information.\n"
"Or add the following to your app.py\n"
"\n"
"from dynaconf import FlaskDynaconf\n"
"app = Flask(__name__)\n"
"FlaskDynaconf(app)\n"
)
exit(1)

path = Path(path)

if env is not None:
Expand Down
2 changes: 0 additions & 2 deletions example/issues/519_underscore_in_name/settings.yml

This file was deleted.

12 changes: 0 additions & 12 deletions example/issues/705_flask_dynaconf_init/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion example/issues/799_negative_numbers/settings.toml

This file was deleted.