Python
Version
Running on Python v3.11.8
Supported languages
Python
Testing framework
Special reminders and implementation details
from pytest import mark as m
from challenge.app import helloWorld
@m.describe("app.py")
class TestHelloWorld:
@m.it("Should return 'Hello World!'")
def test_return_hello_world(self):
assert helloWorld() == 'Hello World!'Included libraries
Write-tests challenges
This template supports write-tests challenges. The reference solution is already written and you write the tests: they must pass on the reference solution and catch every hidden buggy variant. Test runs your tests against the reference solution only, while Verify tests and Submit also run them against the hidden buggy variants. Read Solving a write-tests challenge for the full flow.
- Test runner: pytest
- Import the solution through the
challengepackage, for examplefrom challenge.clamp import clamp. The Run entry (main.py) imports without the prefix (from clamp import clamp). - Name test files
test_*.py. The@m.describe/@m.itdecorators frompytest.markgive your tests readable names in the results panel. - Use
pytest.raisesto pin down error behavior: a missing validation is a classic hidden bug.
A complete example is in Write-tests examples by template.
How to debug
Debugging Python code is essential for every developer. One of the most straightforward yet effective ways to debug is by using print() statements.
Steps to Debug Using Print Statements
Identify the Problem Area: Locate the section of your code where you suspect the problem might be.
Insert
print()Statements: Addprint()statements before and after the suspected problematic code to print out variable values and flow control.Check the Results Output of your tests
Analyze the Output: Look at the values printed in the results console to understand what's going wrong in your code. Adjust your code based on the findings and repeat as necessary.
Here’s an example of how to use print() for debugging:
def calculate_sum(a, b):
print("calculate_sum called with arguments:", a, b) # Log function call
sum_val = a + b
print("Sum after addition:", sum_val) # Log sum calculation
return sum_val
result = calculate_sum(5, 10)
print("Result of calculate_sum:", result) # Log the result