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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions example/-m_case/Makefile
@@ -0,0 +1,4 @@
.PHONY: test

test:
python -m module
1 change: 1 addition & 0 deletions example/app/env.toml
@@ -0,0 +1 @@
FOO = "BAR"
8 changes: 8 additions & 0 deletions example/configure/Makefile
@@ -0,0 +1,8 @@
.PHONY: test

test:
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/
2 changes: 1 addition & 1 deletion example/debug/app.py
Expand Up @@ -5,7 +5,7 @@
settings = Dynaconf(settings_file="settings.toml")


__import__("pudb").set_trace()
# __import__("pudb").set_trace()

foo = settings.store.get("foo")
bar = foo.bar
3 changes: 3 additions & 0 deletions example/issues/705_flask_dynaconf_init/.gitignore
@@ -0,0 +1,3 @@

# Ignore dynaconf secret files
.secrets.*
5 changes: 5 additions & 0 deletions example/issues/705_flask_dynaconf_init/settings.toml
@@ -0,0 +1,5 @@
[development]
TEST_VAR = ""

[default]
TEST_VAR = "a default value"
62 changes: 62 additions & 0 deletions example/runtests.py
@@ -0,0 +1,62 @@
#!/usr/bin/env python3
from __future__ import annotations

import os
import subprocess
import sys
from pathlib import Path

from dynaconf.vendor.tomllib import load


def run_tests():
root_directory = Path(__file__).parent
print("Workdir:", root_directory.absolute())
functional_tests = sorted(list(root_directory.iterdir()))
print("Collected functional tests:", len(functional_tests))
for path in functional_tests:
if path.is_dir():
if path.name in [".", "__pycache__"]:
continue
print("-" * 80)
print("Starting Test on:", path)

env = {**os.environ}
if os.path.exists(path / "env.toml"):
print("Loading env.toml")
_envvars = load(open(path / "env.toml", "rb"))
env.update(_envvars)

if (path / "Makefile").exists():
print("Running make")
subprocess.check_call(["make", "test"], cwd=path, env=env)
continue

if (path / "app.py").exists():
print("Running app.py")
subprocess.check_call(
[sys.executable, "app.py"], cwd=path, env=env
)
continue

if (path / "program.py").exists():
print("Running program.py")
subprocess.check_call(
[sys.executable, "program.py"], cwd=path, env=env
)
continue

if (path / "test.py").exists():
print("Running test.py")
subprocess.check_call(
[sys.executable, "test.py"], cwd=path, env=env
)
continue

exit("WARNING: Can't find Makefile, app.py, test.py, program.py")

print("All Functional tests passed")


if __name__ == "__main__":
run_tests()