Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pytest output results are garbled within pycharm

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?

like image 561
Gerges Avatar asked Dec 17 '18 20:12

Gerges


People also ask

How do I get output in PyCharm?

Open settings by pressing ⌘ , , navigate to Tools | Database | Query Execution | Output and Results.

What is pytest K?

Run tests by keyword expressions pytest -k "MyClass and not method" This will run tests which contain names that match the given string expression (case-insensitive), which can include Python operators that use filenames, class names and function names as variables. The example above will run TestMyClass.

How do I run a specific test in pytest?

Running pytest We can run a specific test file by giving its name as an argument. A specific function can be run by providing its name after the :: characters. Markers can be used to group tests.


1 Answers

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

like image 101
Gerges Avatar answered Sep 29 '22 02:09

Gerges