Skip to content

Coloured Output #62

@JohnPaton

Description

@JohnPaton

Currently I write my tests in unittest, but use pytest as a test runner because the coloured output makes it easier to see what's going on at a glance (plus it just looks better). This could be added to marbles as well, since nicer output is a major feature. Examples I'm thinking of:

  • Green . / red F as tests run:
..........................................F......
  • Green ok / red FAIL in verbose mode:
test_not_found (tests.test_users.TestUpdatePassword) ... ok
test_wrong_password (tests.test_users.TestUpdatePassword) ... ok
test_empty_lists (tests.test_utils.TestDropNones) ... ok
test_empty_strings (tests.test_utils.TestDropNones) ... ok
test_no_nones (tests.test_utils.TestDropNones) ... ok
test_nones (tests.test_utils.TestDropNones) ... ok
test_0_to_plus31 (tests.test_utils.TestFormatPhoneNumber) ... FAIL
test_already_formatted (tests.test_utils.TestFormatPhoneNumber) ... ok
test_bad_input (tests.test_utils.TestFormatPhoneNumber) ... ok
test_dashes (tests.test_utils.TestFormatPhoneNumber) ... ok
test_foreign (tests.test_utils.TestFormatPhoneNumber) ... ok
test_plus (tests.test_utils.TestFormatPhoneNumber) ... ok
test_spaces (tests.test_utils.TestFormatPhoneNumber) ... ok
  • Highlight important bits of failure messages
    • Red FAIL in title to make quick scrolling easier (more visible breaks between mesages)
    • Maybe some color for the actual assertion message ( '+31612345678' != 'this will fail')
    • Syntax highlighting in the source lines or traceback (I might be getting carried away here)
======================================================================
FAIL: test_0_to_plus31 (tests.test_utils.TestFormatPhoneNumber)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/johnpaton/some/path/tests/test_utils.py", line 64, in test_0_to_plus31
    self.assertEqual(output, 'this will fail')
  File "/Users/johnpaton/some/path/venv/subsidy/lib/python3.6/site-packages/marbles/core/marbles.py", line 532, in wrapper
    return attr(*args, msg=annotation, **kwargs)
marbles.core.marbles.ContextualAssertionError: '+31612345678' != 'this will fail'
- +31612345678
+ this will fail


Source (/Users/johnpaton/some/path/tests/test_utils.py):
     63 output = utils.format_phone_number(input)
 >   64 self.assertEqual(output, 'this will fail')
     65 
Locals:
	output=+31612345678
	expected=+31612345678
	input=0612345678


----------------------------------------------------------------------

This might be a good use case for colorama and/or pygments at the expense of another dependency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions