Skip to content
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

pytest-sugar is not working with pytest v5.4.0 (released on March 12th 2020) #187

Closed
MarcBoissonneault opened this issue Mar 12, 2020 · 22 comments · Fixed by #188
Closed

Comments

@MarcBoissonneault
Copy link

pytest-sugar is not working with pytest v5.4.0 (released on March 12th 2020)

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/local/lib/python3.7/site-packages/_pytest/main.py", line 187, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 820, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "/usr/local/lib/python3.7/site-packages/pluggy/hooks.py", line 308, in call_historic
INTERNALERROR>     res = self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/local/lib/python3.7/site-packages/pytest_sugar.py", line 176, in pytest_configure
INTERNALERROR>     sugar_reporter = SugarTerminalReporter(standard_reporter)
INTERNALERROR>   File "/usr/local/lib/python3.7/site-packages/pytest_sugar.py", line 214, in __init__
INTERNALERROR>     self.writer = self._tw
INTERNALERROR> AttributeError: can't set attribute
@GuillaumeFavelier
Copy link
Contributor

GuillaumeFavelier commented Mar 12, 2020

It seems that direct access to self.writer is deprecated:

https://github.com/pytest-dev/pytest/blob/master/src/_pytest/terminal.py#L285-L293

and that self.write() should be used instead of self.writer.write():

https://github.com/pytest-dev/pytest/blob/master/src/_pytest/terminal.py#L361-L362

I suggest:

diff --git a/pytest_sugar.py b/pytest_sugar.py
index c479dab..35d018a 100644
--- a/pytest_sugar.py
+++ b/pytest_sugar.py
@@ -211,7 +211,6 @@ def pytest_report_teststatus(report):
 class SugarTerminalReporter(TerminalReporter):
     def __init__(self, reporter):
         TerminalReporter.__init__(self, reporter.config)
-        self.writer = self._tw
         self.paths_left = []
         self.tests_count = 0
         self.tests_taken = 0
@@ -339,14 +338,14 @@ class SugarTerminalReporter(TerminalReporter):
     def overwrite(self, line, rel_line_num):
         # Move cursor up rel_line_num lines
         if rel_line_num > 0:
-            self.writer.write("\033[%dA" % rel_line_num)
+            self.write("\033[%dA" % rel_line_num)
 
         # Overwrite the line
-        self.writer.write("\r%s" % line)
+        self.write("\r%s" % line)
 
         # Return cursor to original line
         if rel_line_num > 0:
-            self.writer.write("\033[%dB" % rel_line_num)
+            self.write("\033[%dB" % rel_line_num)
 
     def get_max_column_for_test_status(self):
         return (
@@ -389,7 +388,7 @@ class SugarTerminalReporter(TerminalReporter):
         else:
             self.current_lines[path] = " " * (2 + len(fspath))
         self.current_line_nums[path] = self.current_line_num
-        self.writer.write("\r\n")
+        self.write("\r\n")
 
     def reached_last_column_for_test_status(self, report):
         len_line = real_string_length(

@blueyed
Copy link
Collaborator

blueyed commented Mar 13, 2020

@GuillaumeFavelier
Your patch looks good, please consider creating a PR with it.

chris-allan added a commit to chris-allan/omero-web that referenced this issue Mar 14, 2020
rixx added a commit to pretalx/pretalx that referenced this issue Mar 14, 2020
pytest-sugar does not work with current pytest, as per
Teemu/pytest-sugar#187. It's not vital to our test process, so we will
do without. Closes #897.
kowalcj0 added a commit to uktrade/great-cms that referenced this issue Mar 16, 2020
pcrespov pushed a commit to pcrespov/osparc-simcore that referenced this issue Mar 16, 2020
pcrespov pushed a commit to pcrespov/osparc-simcore that referenced this issue Mar 16, 2020
@donbeave
Copy link

Hello!

It looks like all fixes were merged already. Can I ask when the new version with fixes planned to be released?

PrettyWood added a commit to ToucanToco/peakina that referenced this issue Mar 18, 2020
pytest-sugar does not work with new pytest version
Teemu/pytest-sugar#187
Let's just freeze pytest version in the meantime
hoechenberger added a commit to mne-tools/mne-bids that referenced this issue Mar 18, 2020
pytest-sugar currently doesn't support pytest 5.4, see
Teemu/pytest-sugar#187
agramfort pushed a commit to mne-tools/mne-bids that referenced this issue Mar 18, 2020
* TESTS: Try to fix CI

pytest-sugar currently doesn't support pytest 5.4, see
Teemu/pytest-sugar#187

* Fix minimal install

* Update doc env too
pgjones added a commit to pgjones/hypercorn that referenced this issue Mar 20, 2020
9dogs added a commit to 9dogs/tg-odesli-bot that referenced this issue Mar 22, 2020
jcfr added a commit to jcfr/word_cloud that referenced this issue Apr 8, 2020
The version 5.4.0 of pytest introduced a regression preventing pytest-sugar
from working (see [1] and [2])

It has been fixed in pytest (see [3]) and waiting a new release of
pytest is published, this commit updates requirements.

[1] Teemu/pytest-sugar#187
[2] amueller#535 (comment)
[3] pytest-dev/pytest#6986
mafrosis added a commit to mafrosis/jira-offline that referenced this issue Apr 10, 2020
mafrosis added a commit to mafrosis/jira-offline that referenced this issue Apr 10, 2020
mafrosis added a commit to mafrosis/jira-offline that referenced this issue Apr 10, 2020
@Lawouach
Copy link

Hello there,

I'm gettin ga little confused. What's the state of this? Are we waiting on pytest or this plugin to have a fix/release?

Cheers :)

@ankostis
Copy link

On the same page, is it possible for a fix this issue so that pytest-sugar is backward & future compatible to pytest?

@nicoddemus
Copy link
Collaborator

#188 will make pytest-sugar use the recommended API, which is also backward compatible.

Please clarify, it is correct that in pytest 5.4.2 this incompatibility with pytest-sugar hopefully will be fix ?

This is also true, 5.4.2 will also fix this.

@Lawouach
Copy link

Thanks! :)

Right so, until either of them are released, we should limit to pytests 5.4.1 or below, right?

@nicoddemus
Copy link
Collaborator

nicoddemus commented Apr 17, 2020

I think <5.4,>=5.4.2, as this was introduced in 5.4.0. 👍

@Lawouach
Copy link

Lawouach commented Apr 17, 2020

great. thank you.

went for this:

pytest~=5.4,!=5.4.1

@MapleCCC
Copy link

This will work to get pytest-sugar working until this has merged:

pip install -e git+https://github.com/GuillaumeFavelier/pytest-sugar.git@b56fed42d5c3022ff507ab6ce81cda65a3a5f92a#egg=pytest-sugar

It simply installs the version from @GuillaumeFavelier's fork.

For those who don't want to install in editable mode, you can drop the -e option when issuing the command propsed by @truthdoug .

@ankostis
Copy link

Just noting that as of today, latest pytest(5.4.1) & pytest-sugar(0.9.3) in PyPi still fail with:

$ pytest
Test session starts (platform: linux, Python 3.8.2, pytest 5.4.1, pytest-sugar 0.9.3)
rootdir: /project-dir, inifile: setup.cfg
plugins: cov-2.8.1, sphinx-0.2.2, sugar-0.9.3
collecting ... INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/_pytest/main.py", line 191, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/_pytest/main.py", line 246, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/_pytest/main.py", line 257, in pytest_collection
INTERNALERROR>     return session.perform_collect()
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/_pytest/main.py", line 454, in perform_collect
INTERNALERROR>     hook.pytest_collection_modifyitems(
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/_pytest/mark/__init__.py", line 151, in pytest_collection_modifyitems
INTERNALERROR>     deselect_by_mark(items, config)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/_pytest/mark/__init__.py", line 145, in deselect_by_mark
INTERNALERROR>     config.hook.pytest_deselected(items=deselected)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/_pytest/terminal.py", line 431, in pytest_deselected
INTERNALERROR>     self._add_stats("deselected", items)
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/_pytest/terminal.py", line 402, in _add_stats
INTERNALERROR>     self._set_main_color()
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/_pytest/terminal.py", line 1090, in _set_main_color
INTERNALERROR>     self._main_color = self._determine_main_color(bool(unknown_types))
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/_pytest/terminal.py", line 1077, in _determine_main_color
INTERNALERROR>     elif "passed" in stats or not self._is_last_item:
INTERNALERROR>   File ".../.venv/lib/python3.8/site-packages/_pytest/terminal.py", line 496, in _is_last_item
INTERNALERROR>     return len(self._progress_nodeids_reported) == self._session.testscollected
INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'testscollected'


Results (0.57s):
      63 deselected

@jakul
Copy link

jakul commented Apr 29, 2020

I've raised #194 to track that error - this one is fixed

kowalcj0 added a commit to uktrade/directory-tests that referenced this issue May 22, 2020
this is to address incompatibility issues between latest version of
pytest and pytest-sugar
Teemu/pytest-sugar#187
Teemu/pytest-sugar#194
stephanlukasczyk added a commit to se2p/pynguin that referenced this issue Jul 27, 2020
The plugin does currently not work with PyTest 5.4+, see
Teemu/pytest-sugar#187.  Until this issue is
fixed and a new version of the plugin is released, we deactivate it to
upgrade the dependencies.
pgjones added a commit to pgjones/quart-trio that referenced this issue Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.