From 97f040512aacd7b6c99397a36339d3cb55e7c5b3 Mon Sep 17 00:00:00 2001 From: Rodrigo Ceballos Date: Wed, 31 May 2023 23:17:09 -0400 Subject: [PATCH] docs(README.md): add run_package_tests --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index ed9af65..d36b4fe 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,39 @@ three newest temporary directories): pytest --keep-baked-projects ``` +## Automatic Testing of Baked Package +If you're baked package has automatic tests, you can also run those tests automatically like so: + +``` +import os +import subprocess +import tempfile + + +def run_package_tests(path): + # Go to the given path + os.chdir(path) + + # Create a temporary directory as the environment + with tempfile.TemporaryDirectory() as temp_dir: + # Create a virtual environment + subprocess.check_call(["python3", "-m", "venv", temp_dir]) + + # Activate the virtual environment + activate_script = os.path.join(temp_dir, 'bin', 'activate') + + # Install the Python package + subprocess.check_call(["bash", "-c", f"source {activate_script} && pip install ."]) + + # Run pytest + subprocess.check_call(["bash", "-c", f"source {activate_script} && pytest ."]) + + +def test_bake_project(cookies): + result = cookies.bake() + run_package_tests(result._project_dir) +``` + # Community Contributions are very welcome! If you encounter any problems, please [file