Skip to content

docs(README.md): add run_package_tests #65

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you're baked package has automatic tests, you can also run those tests automatically like so:
If your 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
Expand Down