Skip to content

Codewars Python Test Framework

Blind4Basics edited this page Jan 6, 2018 · 17 revisions

Basic Setup

test.describe("Example Tests")
test.it("Example Test Case")
test.assert_equals(add(1, 1), 2, "Optional Message")
print("<COMPLETEDIN::>")
print("<COMPLETEDIN::>")

Assertions

TODO Improve the descriptions while keeping them simple.

test.assert_equals(actual, expected, message)

Checks that the actual value equals the expected value.

test.assert_not_equals(actual, unexpected, message)

Checks that the actual value does not equal the expected value.

test.expect_error(message, function)

Checks that function throws`.

test.expect(passed, message)

test.expect(passed, message, allow_raise=True)

test.expect(passed, allow_raise=True)

Checks that passed is truthy. Note that the test suite will continue its execution if the keyword allow_raise isn't manually set to True.

The print("<COMPLETEDIN::>") element:

In Python, the Test.describe and Test.it will concatenate themselves if you do not use this element to close the blocks. Note that the statement will not show up in the console.

Test.describe("1")
Test.it("A")
Test.describe("2")
Test.it("B")
Test.it("C")

Leads to:

1
  A
    2
      B
      C


Test.describe("1")
Test.it("A")
print("<COMPLETEDIN::>")          #  <-  close it
print("<COMPLETEDIN::>")          #  <-  close describe
Test.describe("2")
Test.it("B")
print("<COMPLETEDIN::>")          #  <-  close it
Test.it("C")
print("<COMPLETEDIN::>")          #  <-  close it
print("<COMPLETEDIN::>")          #  <-  close describe

Leads to:

1
  A
2
  B
  C
Clone this wiki locally