New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use alternative to ANSI control sequences in Jupyter notebooks #195
Conversation
def test_color(monkeypatch, color_test_cases): | ||
color, expected = color_test_cases | ||
# ``None`` and ``""`` are skipped | ||
if not color: | ||
pytest.skip("{0} - unsupported case".format(repr(color))) | ||
|
||
monkeypatch.setattr(sys.stdout, "isatty", lambda: True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there is an easier way to do this over and over?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible to make this patch at the module level, like this:
@pytest.fixture(autouse=True)
def isatty_true(monkeypatch):
monkeypatch.setattr(sys.stdout, "isatty", lambda: True)
From the docs: https://docs.pytest.org/en/6.2.x/monkeypatch.html#global-patch-example-preventing-requests-from-remote-operations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few comments; Also, code conflict should be resolved.
def test_color(monkeypatch, color_test_cases): | ||
color, expected = color_test_cases | ||
# ``None`` and ``""`` are skipped | ||
if not color: | ||
pytest.skip("{0} - unsupported case".format(repr(color))) | ||
|
||
monkeypatch.setattr(sys.stdout, "isatty", lambda: True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible to make this patch at the module level, like this:
@pytest.fixture(autouse=True)
def isatty_true(monkeypatch):
monkeypatch.setattr(sys.stdout, "isatty", lambda: True)
From the docs: https://docs.pytest.org/en/6.2.x/monkeypatch.html#global-patch-example-preventing-requests-from-remote-operations
@@ -13,7 +13,7 @@ pypi_pwd := $(shell grep password ~/.pypirc | awk -F"= " '{ print $$2 }') | |||
|
|||
flake: | |||
@echo "$(OK_COLOR)==> Linting code ...$(NO_COLOR)" | |||
@poetry run flake8 --ignore=F821,E501 . | |||
@poetry run flake8 --ignore=F821,E501,W503 . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W504 and W503 are contradictory
@pytest.fixture(autouse=True) | ||
def isatty_true(monkeypatch): | ||
monkeypatch.setattr(sys.stdout, "isatty", lambda: True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this doesn't correctly patch capsys
so more monkeypatches are needed within test cases that use capsys
. Do you have another idea?
However, this works fine for a bunch of tests not using capsys
that would otherwise raise a warning. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few comments; sorry for such a delay in reviews, having very busy weeks right now.
@pavdmyt no worries for the delay. I hope my changes fit your requests :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor issue, otherwise LGTM 👍
Second try of #193 and fixing #176
sys.stdout.isatty
to pretend output is a terminalTerminal:
Jupyter: