Cylc-flow: test_host_select unit tests fail locally when run within the IDE

Created on 24 Jul 2019  路  6Comments  路  Source: cylc/cylc-flow

Describe the bug

The test_host_select unit test is failing when executed in the IDE. I suspect it is due to terminal colours tokens added, which could mean that in the IDE the current approach to identify whether it is running in a terminal or not is missing something.

Release version(s) and/or repository branch(es) affected?

master

Steps to reproduce the bug

Simply run test_host_select unit test in PyCharm (not sure if it would pass on Visual Studio/Eclipse/etc). The tests pass fine on the terminal.

Expected behavior

Successfully run and debug the tests.

Screenshots

image

Updated screenshot:

image

Additional context

Value copied while debugging the test:

'{
    "load:1": 0.86,
    "load:5": 0.43,
    "load:15": 0.56,
    "memory": 1610200
}
'

Pull requests welcome!
This is an Open Source project - please consider contributing a bug fix
yourself (please read CONTRIBUTING.md before starting any work though).

bug?

All 6 comments

Still same issue, only test to fail on my IDE.

image

Found that removing the color_init() call in terminal.py, it passes.

image

But I think that probably breaks colors in the terminal. As this is not breaking anything, only a unit test in my IDE, moving to another release :+1:

The test above was removed. But there are two new tests (test_rankings, test_unreasonable_rankings), also related to host selection, that fail now. Same kind of error, extra character at the end of the string when tests are run under PyCharm.

image

image

Closed by #3489

And tested the PR #3570 , which fixes the unit tests in the IDE.

image

Tested today after SoD and other PR's. Thought maybe it had been fixed. But still similar issue, now in two tests.

image

Ok, so there are two things here.

1) The pycharm terminal behaves differently to normal terminals.
2) There is a vulnerability in the cylc psutil to junk characters.

I've no idea how to solve problem (1), however, perhaps there is some merit to addressing problem (2).

The main source of problem (2) is the horrible shell profile files some people write, for example I found lines like this in one user's bashrc:

echo "Hello $USER"
echo "It is $(date)"

To protect against host_select ignores any characters which come before the first {. We could extend this to ignore any characters after the last }.

There is also the option of printing a special start/stop marker e.g:

===start of data===
{
    "x": "y"
}
===end of data===

Note that this is how we copy zmq-curve keys back from the server.

However, this has the distinct disadvantage that it produces invalid JSON which has to be parsed in a special way.

There may be a third option to just selectively disable colour in the cylc psutil script which would address the pycharm issue but, however, wouldn't address other issues which are far more common.

Was this page helpful?
0 / 5 - 0 ratings