Code Runner is a lightweight Flask-based microservice designed to execute Python scripts and run unit tests for the RPL service application. It is primarily used to facilitate the exercise delivery functionality by allowing users to submit scripts along with test cases and receive automated test results.
- Accepts Python scripts and corresponding test cases via a JSON API.
- Runs unit tests using
pytest
in a sandboxed environment. - Returns structured test results including success and failure reports.
- Minimal dependencies (only Flask and Pytest required).
- Clone the repository:
git clone https://github.com/WillyTonkas/code-runner.git cd code-runner
- Install dependencies:
pip install -r requirements.txt
- Run the application:
python app.py
Send a POST
request with a JSON body containing:
{
"script": "def add(a, b):\n return a + b",
"tests": "from script import add\ndef test_add():\n assert add(2, 3) == 5\n assert add(-1, 1) == 0"
}
{
"stdout": "...",
"stderr": "...",
"returncode": 0
}
stdout
: Standard output frompytest
.stderr
: Error messages if any.returncode
: Exit code (0 means success, non-zero indicates failure).
This application is containerized and can be deployed via Docker. To build and run the container:
# Build the Docker image
docker build -t code-runner .
# Run the container
docker run -p 5000:5000 code-runner
This project is licensed under the MIT License.