A local batch testing and judging tool for Online Judge (OJ) problems, designed for TAs, problem setters, and students.
Easily manage test cases, debug solutions, and generate detailed feedback without uploading to the OJ platform.
- Automatic test case discovery: Reads
.in/.outfiles from problem folders. - Batch testing: Runs all test cases for each problem automatically.
- Detailed logging: Shows input, expected output, and actual output for each test.
- No hardcoded paths: Uses the current Python interpreter for subprocesses.
- Easy to extend: Add new problems and test cases by simply adding files.
Lab/
├── Q1/
│ ├── 1.in
│ ├── 1.out
│ └── ...
├── Q2/
│ └── ...
├── Q3/
│ └── ...
├── Q4/
│ └── ...
├── Q5/
│ └── ...
├── q1.py
├── q2.py
├── q3.py
├── q4.py
├── test_q1.py
├── test_q2.py
├── test_q3.py
├── test_q4.py
└── ...
Q1/,Q2/, ...: Folders containing input/output test cases for each problem (can extend toQ5/,Q6/as needed).q1.py,q2.py, ...: Your solution scripts.test_q1.py,test_q2.py, ...: Pytest scripts for automated testing.
-
Install Python 3 (if not already installed).
-
Install dependencies:
pip install -r requirements.txt
or
pip install pytest loguru
(You need
pytestandloguru.) -
Add your solution and test cases:
- Place your solution (e.g.,
q1.py) in the root directory. - Place test cases in the corresponding folder (e.g.,
Q1/1.in,Q1/1.out).
- Place your solution (e.g.,
-
Run all tests:
pytest -v
-
Run a single test file:
pytest -v test_q1.py
-
See detailed logs:
- Use the
-sflag to show print/log output:pytest -v -s
- Use the
To avoid code duplication, all test scripts now use the shared utils.py for:
- Reading test case files
- Discovering all
.in/.outpairs - Running and checking subprocess output
Example usage in a test file:
from utils import read_file, get_in_out_files, run_and_check
Q_DIR = os.path.join(os.path.dirname(__file__), "Q1")
PYTHON = sys.executable
TARGET = os.path.join(os.path.dirname(__file__), "q1.py")
def test_q1_cases():
for base, in_file, out_file in get_in_out_files(Q_DIR):
input_data = read_file(in_file)
expected_output = read_file(out_file)
run_and_check(PYTHON, TARGET, input_data, expected_output)This makes all test scripts concise and easy to maintain.
- Download OJ test cases and organize them into folders as shown above.
- Use or adapt the provided
test_qX.pyscripts to automate local grading. - Share this framework with students for self-testing before submission.
MIT License. See LICENSE for details.
SUNG-CHE, LIN