8

I am using pytest with pycharm, but when I run the test, I get the test and results garbled within the pycharm console, here is an example output:

============================= test session starts ==============================
platform linux -- Python 3.6.6, pytest-4.0.1, ....
cachedir: .pytest_cache
rootdir: ....
collecting ... collected 14 items

tests/test_ops.py::test_layer 
tests/test_ops.py::test_layer_with_input_shape 
tests/test_ops.py::test_layer_with_batch_input 
tests/test_ops.py::test_layer_with_batch_size_and_input_shape 
tests/test_ops.py::test_rshift_input_layer 
tests/test_ops.py::test_rshift_input_list 
tests/test_ops.py::test_rshift_two_layers 
tests/test_ops.py::test_rshift_input_and_two_layers 
tests/test_ops.py::test_rshift_input_and_deferred_layer 
tests/test_ops.py::test_rshift_input_list_and_deferred_layer 
tests/test_ops.py::test_rshift_deferred_layer_to_layer 
tests/test_ops.py::test_rshift_layer_to_deferred_layer 
tests/test_ops.py::test_rshift_layer_to_int 
tests/test_ops.py::test_rshift_layer_to_int_with_inputs 

========================== 14 passed in 1.27 seconds ===========================PASSED                                     [  7%]PASSED                    [ 14%]Tensor_rshift_layer
PASSED                    [ 21%]Tensor_rshift_layer
PASSED     [ 28%]Tensor_rshift_layer
PASSED                        [ 35%]Tensor_rshift_layer
PASSED                         [ 42%]list_rshift_layer
PASSED                         [ 50%]layer_rshift_layer
PASSED               [ 57%]Tensor_rshift_layer
PASSED           [ 64%]layer_rshift_layer
Tensor_rshift_layer
PASSED      [ 71%]layer_rshift_layer
list_rshift_layer
PASSED            [ 78%]layer_rshift_layer
layer_rshift_layer
PASSED            [ 85%]layer_rshift_layer
layer_rshift_layer
PASSED                       [ 92%]layer_rshift_int
layer_rshift_layer
PASSED           [100%]layer_rshift_int
layer_rshift_layer
Tensor_rshift_layer

This is rather not pretty, and the result are printed after the test functions report.

This is how it should look like when I run pytest from the terminal:

$ pytest -v -p no:warnings --color=yes

================================ test session starts ================================
platform linux -- Python 3.6.6, pytest-4.0.1, ...
cachedir: .pytest_cache
rootdir: ...
collected 14 items                                                                  

tests/test_ops.py::test_layer PASSED                                          [  7%]
tests/test_ops.py::test_layer_with_input_shape PASSED                         [ 14%]
tests/test_ops.py::test_layer_with_batch_input PASSED                         [ 21%]
tests/test_ops.py::test_layer_with_batch_size_and_input_shape PASSED          [ 28%]
tests/test_ops.py::test_rshift_input_layer PASSED                             [ 35%]
tests/test_ops.py::test_rshift_input_list PASSED                              [ 42%]
tests/test_ops.py::test_rshift_two_layers PASSED                              [ 50%]
tests/test_ops.py::test_rshift_input_and_two_layers PASSED                    [ 57%]
tests/test_ops.py::test_rshift_input_and_deferred_layer PASSED                [ 64%]
tests/test_ops.py::test_rshift_input_list_and_deferred_layer PASSED           [ 71%]
tests/test_ops.py::test_rshift_deferred_layer_to_layer PASSED                 [ 78%]
tests/test_ops.py::test_rshift_layer_to_deferred_layer PASSED                 [ 85%]
tests/test_ops.py::test_rshift_layer_to_int PASSED                            [ 92%]
tests/test_ops.py::test_rshift_layer_to_int_with_inputs PASSED                [100%]

============================= 14 passed in 1.25 seconds =============================

Is there a way to configure pycharm's console or pytest so that it prints pytest results correctly within pycharm?

Gerges
  • 6,269
  • 2
  • 22
  • 44
  • Have you looked at the terminal settings for pycharm? You can direct it to use whatever shell you want, which may point somewhere different than the shell you're comparing it to. – TemporalWolf Dec 17 '18 at 20:50
  • The output is OK within the terminal (even pycharm's terminal), however it get garbeled within the console, i..e when i run it from configurations, and results appear under `4: Run`. Is there a way to configure this? – Gerges Dec 17 '18 at 21:20
  • Under Run -> Edit Configurations there is a defaults category. The most promising things I saw was "emulate terminal in output console" and that it specifies `PYTHONUNBUFFERED=1`... no idea if those will help you, but that's probably the best place to look – TemporalWolf Dec 17 '18 at 22:04
  • 1
    Please vote for the relevant ticket in PyCharm's bug tracker: [PY-27169](https://youtrack.jetbrains.com/issue/PY-27169). – Pavel Karateev Dec 20 '18 at 07:40

1 Answers1

7

The output looks better when I unchecked "Track running test" as in the photo here:enter image description here

Gerges
  • 6,269
  • 2
  • 22
  • 44
  • 1
    +1 For me it was not a hamburger dots thing but more like a "cog" symbol which reveals a drop-down menu: https://i.stack.imgur.com/egbb0.png – wim Dec 31 '18 at 22:30
  • I'm using the material theme. Its comprehensive, customizable and beautiful. I do recommend. – Gerges Dec 31 '18 at 22:40
  • @Gerges - thanks for sharing "material theme" just downloaded it and its great. Quick question though, how do you get coloured console output for tests, for me its all white text, no blue for percentages, or yellow for separators for example (https://imgur.com/a/SVBndAo). Thanks! – Carlos Aug 17 '19 at 19:34
  • https://stackoverflow.com/questions/17069007/how-do-i-force-pytest-to-write-color-output – Gerges Aug 17 '19 at 20:34