handle and display AssertionErrors by ggorlen · Pull Request #5 · codewars/python-test-framework · GitHub
Skip to content

handle and display AssertionErrors#5

Merged
kazk merged 1 commit intocodewars:masterfrom
ggorlen:add-assertion-error
Jun 12, 2020
Merged

handle and display AssertionErrors#5
kazk merged 1 commit intocodewars:masterfrom
ggorlen:add-assertion-error

Conversation

@ggorlen
Copy link
Copy Markdown
Contributor

@ggorlen ggorlen commented Jun 12, 2020

This allows frameworks like numpy to raise AssertionErrors which can be handled in a similar way to in-suite assertion errors.

import numpy as np
import test_framework as test

@test.describe('Example Tests')
def example_tests():
    @test.it('Example Test Case')
    def example_test_case():
        actual = np.reshape(range(16), [4, 4])
        expected = np.reshape(range(1, 17), [4, 4])
        np.testing.assert_equal(expected, actual)

which produces:

<DESCRIBE::>Example Tests

<IT::>Example Test Case

<FAILED::><:LF:>Arrays are not equal<:LF:><:LF:>Mismatched elements: 16 / 16 (100%)<:LF:>Max absolute difference: 1<:LF:>Max relative difference: 1.<:LF:> x: array([[ 1,  2,  3,  4],<:LF:>       [ 5,  6,  7,  8],<:LF:>       [ 9, 10, 11, 12],<:LF:>       [13, 14, 15, 16]])<:LF:> y: array([[ 0,  1,  2,  3],<:LF:>       [ 4,  5,  6,  7],<:LF:>       [ 8,  9, 10, 11],<:LF:>       [12, 13, 14, 15]])

<COMPLETEDIN::>281.39

<COMPLETEDIN::>287.13

Copy link
Copy Markdown
Member

@kazk kazk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
image

Thanks, Greg!

@kazk kazk merged commit e5a0195 into codewars:master Jun 12, 2020
@kazk
Copy link
Copy Markdown
Member

kazk commented Jun 17, 2020

@ggorlen
Copy link
Copy Markdown
Contributor Author

ggorlen commented Jun 17, 2020

I knew it seemed too easy! I'll also take a look today, thanks for the catch.

@Blind4Basics
Copy link
Copy Markdown
Contributor

that would require to decorate all numpy assertions after the import, no?

@kazk
Copy link
Copy Markdown
Member

kazk commented Jul 8, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants