src/bootstrap.py is a script runner that allows you to run any test script with zero cognitive overhead, automatically handling all environment setup.
python src/bootstrap.py [script_path] [script_arguments...]The script path can be:
- Relative to the project root:
unit_test/memory_manager_single_test.py - Relative to the current directory:
../tests/test_convert_rest.py - Absolute path:
/path/to/your/script.py
# Run memory manager test
python src/bootstrap.py unit_test/memory_manager_single_test.py
# Run test with relative path
python src/bootstrap.py ../tests/test_convert_rest.py
# Run test with arguments
python src/bootstrap.py unit_test/memory_manager_single_test.py --verbose# Run dynamic memory evaluation
python src/bootstrap.py evaluation/dynamic_memory_evaluation/locomo_eval.py
# Run evaluation with dataset argument
python src/bootstrap.py evaluation/dynamic_memory_evaluation/locomo_eval.py --dataset small# Run algorithm debugging script
python src/bootstrap.py tests/algorithms/debug_my_model.py
# Run script with config file
python src/bootstrap.py tests/algorithms/debug_my_model.py --config config.json# Run Bootstrap test template to learn how to use DI and MongoDB
python src/bootstrap.py tests/bootstrap_test_template.pySpecify the environment variable file to load (default: .env)
python src/bootstrap.py your_script.py --env-file .env.testEnable Mock mode (for testing and development)
python src/bootstrap.py your_script.py --mockSet to true to enable Mock mode
MOCK_MODE=true python src/bootstrap.py your_script.pyThe project provides a complete test template tests/bootstrap_test_template.py that demonstrates how to:
- Use dependency injection: Get singleton objects via
get_bean_by_type()andget_bean() - Work with MongoDB: Use the repository pattern for database queries and operations
- Integration testing: Combine multiple components for comprehensive testing
The template includes examples like:
# Get MongoDB repository
from core.di.utils import get_bean_by_type
repo = get_bean_by_type(MemCellRawRepository)
# Query data
memcells = await repo.find_all(limit=5)
total_count = await repo.count_all()Run your scripts directly:
python src/bootstrap.py your_script.pyStart by running the test template to understand the project structure:
python src/bootstrap.py tests/bootstrap_test_template.pyUse Mock mode during development:
python src/bootstrap.py your_script.py --mockSpecify different environment files in continuous integration:
python src/bootstrap.py test_script.py --env-file .env.ciIf you encounter ImportError: attempted relative import with no known parent package error:
- Bootstrap will automatically detect and switch to module mode
- No manual intervention needed, the script will automatically retry
If you encounter other module import errors, check:
- Whether you're executing from the project root directory
- Whether the
.envfile exists and is configured correctly
If the target script fails to execute:
- Check if the script path is correct
- Confirm the script itself has no syntax errors