grantjenks / blue

The slightly less uncompromising Python code formatter.
https://blue.readthedocs.io/
Other
387 stars 21 forks source link

test_good_dirs fails with strange error #72

Closed mcepl closed 2 years ago

mcepl commented 2 years ago

When packaging for openSUSE (after applying all patches from #66, so that is not the issue) I get these errors:

[   28s] + PYTHONPATH=/home/abuild/rpmbuild/BUILDROOT/python-blue-0.8.0-0.x86_64/usr/lib/python3.9/site-packages
[   28s] + PYTHONDONTWRITEBYTECODE=1
[   28s] + pytest-3.9 --ignore=_build.python39 --ignore=_build.python310 --ignore=_build.python38 -v
[   28s] ============================= test session starts ==============================
[   28s] platform linux -- Python 3.9.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /usr/bin/python3.9
[   28s] cachedir: .pytest_cache
[   28s] rootdir: /home/abuild/rpmbuild/BUILD/blue-0.8.0, configfile: tox.ini, testpaths: blue, docs, tests
[   29s] collecting ... collected 8 items
[   29s] 
[   29s] tests/test_blue.py::test_good_dirs[config_setup] FAILED                  [ 12%]
[   29s] tests/test_blue.py::test_good_dirs[config_tox] FAILED                    [ 25%]
[   29s] tests/test_blue.py::test_good_dirs[config_blue] FAILED                   [ 37%]
[   29s] tests/test_blue.py::test_good_dirs[config_pyproject] FAILED              [ 50%]
[   29s] tests/test_blue.py::test_good_dirs[good_cases] FAILED                    [ 62%]
[   29s] tests/test_blue.py::test_bad_dirs[bad_cases] FAILED                      [ 75%]
[   29s] tests/test_blue.py::test_main PASSED                                     [ 87%]
[   29s] tests/test_blue.py::test_version PASSED                                  [100%]
[   29s] 
[   29s] =================================== FAILURES ===================================
[   29s] _________________________ test_good_dirs[config_setup] _________________________
[   29s] 
[   29s] monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f702f5393a0>
[   29s] test_dir = PosixPath('/home/abuild/rpmbuild/BUILD/blue-0.8.0/tests/config_setup')
[   29s] 
[   29s]     @pytest.mark.parametrize(
[   29s]         'test_dir',
[   29s]         [
[   29s]             'config_setup',
[   29s]             'config_tox',
[   29s]             'config_blue',
[   29s]             'config_pyproject',
[   29s]             'good_cases',
[   29s]         ],
[   29s]     )
[   29s]     def test_good_dirs(monkeypatch, test_dir):
[   29s]         test_dir = tests_dir / test_dir
[   29s]         monkeypatch.chdir(test_dir)
[   29s]         monkeypatch.setattr('sys.argv', ['blue', '--check', '.'])
[   29s]         for path in test_dir.rglob('*'):
[   29s]             path.touch()  # Invalidate file caches in Blue.
[   29s]         black.find_project_root.cache_clear()
[   29s]         with pytest.raises(SystemExit) as exc_info:
[   29s]             asyncio.set_event_loop(asyncio.new_event_loop())
[   29s]             blue.main()
[   29s] >       assert exc_info.value.code == 0
[   29s] E       assert 123 == 0
[   29s] E         +123
[   29s] E         -0
[   29s] 
[   29s] /home/abuild/rpmbuild/BUILD/blue-0.8.0/tests/test_blue.py:32: AssertionError
[   29s] ----------------------------- Captured stderr call -----------------------------
[   29s] error: cannot format example.py: list_comments() got an unexpected keyword argument 'preview'
[   29s] 
[   29s] Oh no! πŸ’₯ πŸ’” πŸ’₯
[   29s] 1 file would fail to reformat.
[   29s] __________________________ test_good_dirs[config_tox] __________________________
[   29s] 
[   29s] monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f702f5b0070>
[   29s] test_dir = PosixPath('/home/abuild/rpmbuild/BUILD/blue-0.8.0/tests/config_tox')
[   29s] 
[   29s]     @pytest.mark.parametrize(
[   29s]         'test_dir',
[   29s]         [
[   29s]             'config_setup',
[   29s]             'config_tox',
[   29s]             'config_blue',
[   29s]             'config_pyproject',
[   29s]             'good_cases',
[   29s]         ],
[   29s]     )
[   29s]     def test_good_dirs(monkeypatch, test_dir):
[   29s]         test_dir = tests_dir / test_dir
[   29s]         monkeypatch.chdir(test_dir)
[   29s]         monkeypatch.setattr('sys.argv', ['blue', '--check', '.'])
[   29s]         for path in test_dir.rglob('*'):
[   29s]             path.touch()  # Invalidate file caches in Blue.
[   29s]         black.find_project_root.cache_clear()
[   29s]         with pytest.raises(SystemExit) as exc_info:
[   29s]             asyncio.set_event_loop(asyncio.new_event_loop())
[   29s]             blue.main()
[   29s] >       assert exc_info.value.code == 0
[   29s] E       assert 123 == 0
[   29s] E         +123
[   29s] E         -0
[   29s] 
[   29s] /home/abuild/rpmbuild/BUILD/blue-0.8.0/tests/test_blue.py:32: AssertionError
[   29s] ----------------------------- Captured stderr call -----------------------------
[   29s] error: cannot format example.py: list_comments() got an unexpected keyword argument 'preview'
[   29s] 
[   29s] Oh no! πŸ’₯ πŸ’” πŸ’₯
[   29s] 1 file would fail to reformat.
[   29s] _________________________ test_good_dirs[config_blue] __________________________
[   29s] 
[   29s] monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f702f5aa550>
[   29s] test_dir = PosixPath('/home/abuild/rpmbuild/BUILD/blue-0.8.0/tests/config_blue')
[   29s] 
[   29s]     @pytest.mark.parametrize(
[   29s]         'test_dir',
[   29s]         [
[   29s]             'config_setup',
[   29s]             'config_tox',
[   29s]             'config_blue',
[   29s]             'config_pyproject',
[   29s]             'good_cases',
[   29s]         ],
[   29s]     )
[   29s]     def test_good_dirs(monkeypatch, test_dir):
[   29s]         test_dir = tests_dir / test_dir
[   29s]         monkeypatch.chdir(test_dir)
[   29s]         monkeypatch.setattr('sys.argv', ['blue', '--check', '.'])
[   29s]         for path in test_dir.rglob('*'):
[   29s]             path.touch()  # Invalidate file caches in Blue.
[   29s]         black.find_project_root.cache_clear()
[   29s]         with pytest.raises(SystemExit) as exc_info:
[   29s]             asyncio.set_event_loop(asyncio.new_event_loop())
[   29s]             blue.main()
[   29s] >       assert exc_info.value.code == 0
[   29s] E       assert 123 == 0
[   29s] E         +123
[   29s] E         -0
[   29s] 
[   29s] /home/abuild/rpmbuild/BUILD/blue-0.8.0/tests/test_blue.py:32: AssertionError
[   29s] ----------------------------- Captured stderr call -----------------------------
[   29s] error: cannot format example.py: list_comments() got an unexpected keyword argument 'preview'
[   29s] 
[   29s] Oh no! πŸ’₯ πŸ’” πŸ’₯
[   29s] 1 file would fail to reformat.
[   29s] _______________________ test_good_dirs[config_pyproject] _______________________
[   29s] 
[   29s] monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f702f5b4b20>
[   29s] test_dir = PosixPath('/home/abuild/rpmbuild/BUILD/blue-0.8.0/tests/config_pyproject')
[   29s] 
[   29s]     @pytest.mark.parametrize(
[   29s]         'test_dir',
[   29s]         [
[   29s]             'config_setup',
[   29s]             'config_tox',
[   29s]             'config_blue',
[   29s]             'config_pyproject',
[   29s]             'good_cases',
[   29s]         ],
[   29s]     )
[   29s]     def test_good_dirs(monkeypatch, test_dir):
[   29s]         test_dir = tests_dir / test_dir
[   29s]         monkeypatch.chdir(test_dir)
[   29s]         monkeypatch.setattr('sys.argv', ['blue', '--check', '.'])
[   29s]         for path in test_dir.rglob('*'):
[   29s]             path.touch()  # Invalidate file caches in Blue.
[   29s]         black.find_project_root.cache_clear()
[   29s]         with pytest.raises(SystemExit) as exc_info:
[   29s]             asyncio.set_event_loop(asyncio.new_event_loop())
[   29s]             blue.main()
[   29s] >       assert exc_info.value.code == 0
[   29s] E       assert 123 == 0
[   29s] E         +123
[   29s] E         -0
[   29s] 
[   29s] /home/abuild/rpmbuild/BUILD/blue-0.8.0/tests/test_blue.py:32: AssertionError
[   29s] ----------------------------- Captured stderr call -----------------------------
[   29s] error: cannot format example.py: list_comments() got an unexpected keyword argument 'preview'
[   29s] 
[   29s] Oh no! πŸ’₯ πŸ’” πŸ’₯
[   29s] 1 file would fail to reformat.
[   29s] __________________________ test_good_dirs[good_cases] __________________________
[   29s] 
[   29s] monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f702f5eaee0>
[   29s] test_dir = PosixPath('/home/abuild/rpmbuild/BUILD/blue-0.8.0/tests/good_cases')
[   29s] 
[   29s]     @pytest.mark.parametrize(
[   29s]         'test_dir',
[   29s]         [
[   29s]             'config_setup',
[   29s]             'config_tox',
[   29s]             'config_blue',
[   29s]             'config_pyproject',
[   29s]             'good_cases',
[   29s]         ],
[   29s]     )
[   29s]     def test_good_dirs(monkeypatch, test_dir):
[   29s]         test_dir = tests_dir / test_dir
[   29s]         monkeypatch.chdir(test_dir)
[   29s]         monkeypatch.setattr('sys.argv', ['blue', '--check', '.'])
[   29s]         for path in test_dir.rglob('*'):
[   29s]             path.touch()  # Invalidate file caches in Blue.
[   29s]         black.find_project_root.cache_clear()
[   29s]         with pytest.raises(SystemExit) as exc_info:
[   29s]             asyncio.set_event_loop(asyncio.new_event_loop())
[   29s]             blue.main()
[   29s] >       assert exc_info.value.code == 0
[   29s] E       assert 123 == 0
[   29s] E         +123
[   29s] E         -0
[   29s] 
[   29s] /home/abuild/rpmbuild/BUILD/blue-0.8.0/tests/test_blue.py:32: AssertionError
[   29s] ----------------------------- Captured stderr call -----------------------------
[   29s] error: cannot format tdq_docstrings.py: list_comments() got an unexpected keyword argument 'preview'
[   29s] error: cannot format decorators.py: list_comments() got an unexpected keyword argument 'preview'
[   29s] error: cannot format demo.py: list_comments() got an unexpected keyword argument 'preview'
[   29s] 
[   29s] Oh no! πŸ’₯ πŸ’” πŸ’₯
[   29s] 3 files would fail to reformat.
[   29s] ___________________________ test_bad_dirs[bad_cases] ___________________________
[   29s] 
[   29s] monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f702f4898e0>
[   29s] test_dir = PosixPath('/home/abuild/rpmbuild/BUILD/blue-0.8.0/tests/bad_cases')
[   29s] 
[   29s]     @pytest.mark.parametrize(
[   29s]         'test_dir',
[   29s]         ['bad_cases'],
[   29s]     )
[   29s]     def test_bad_dirs(monkeypatch, test_dir):
[   29s]         test_dir = tests_dir / test_dir
[   29s]         monkeypatch.chdir(test_dir)
[   29s]         monkeypatch.setattr('sys.argv', ['blue', '--check', '.'])
[   29s]         for path in test_dir.rglob('*'):
[   29s]             path.touch()  # Invalidate file caches in Blue.
[   29s]         black.find_project_root.cache_clear()
[   29s]         with pytest.raises(SystemExit) as exc_info:
[   29s]             asyncio.set_event_loop(asyncio.new_event_loop())
[   29s]             blue.main()
[   29s] >       assert exc_info.value.code == 1
[   29s] E       assert 123 == 1
[   29s] E         +123
[   29s] E         -1
[   29s] 
[   29s] /home/abuild/rpmbuild/BUILD/blue-0.8.0/tests/test_blue.py:49: AssertionError
[   29s] ----------------------------- Captured stderr call -----------------------------
[   29s] error: cannot format sdq_docstrings.py: list_comments() got an unexpected keyword argument 'preview'
[   29s] error: cannot format tsq_docstrings.py: list_comments() got an unexpected keyword argument 'preview'
[   29s] error: cannot format ssq_docstrings.py: list_comments() got an unexpected keyword argument 'preview'
[   29s] error: cannot format demo.py: list_comments() got an unexpected keyword argument 'preview'
[   29s] 
[   29s] Oh no! πŸ’₯ πŸ’” πŸ’₯
[   29s] 4 files would fail to reformat.
[   29s] =========================== short test summary info ============================
[   29s] FAILED tests/test_blue.py::test_good_dirs[config_setup] - assert 123 == 0
[   29s] FAILED tests/test_blue.py::test_good_dirs[config_tox] - assert 123 == 0
[   29s] FAILED tests/test_blue.py::test_good_dirs[config_blue] - assert 123 == 0
[   29s] FAILED tests/test_blue.py::test_good_dirs[config_pyproject] - assert 123 == 0
[   29s] FAILED tests/test_blue.py::test_good_dirs[good_cases] - assert 123 == 0
[   29s] FAILED tests/test_blue.py::test_bad_dirs[bad_cases] - assert 123 == 1
[   29s] ========================= 6 failed, 2 passed in 0.22s ==========================
[   29s] error: Bad exit status from /var/tmp/rpm-tmp.JscPCz (%check)

Complete build log with all packages used and steps taken.

What is the most interesting (in my opinion) is that list_comments() function (if I am not mistaken) own function of this package, so it is strange that tests call it incorrectly. Also, it is strange, that I cannot find the word preview in the exploded packages.

What’s going on, please?

warsaw commented 2 years ago

Confirmed. This is a blocker for 0.9.0

warsaw commented 2 years ago

For me this only happens with the Python 3.7 environment, reproducible locally with tox -e py37

warsaw commented 2 years ago

Notice the draft PR in #73

What is super weird is that the test suite only fails with Python 3.6 and 3.7, and there only with --check and not --diff. Even stranger, if you activate the py36 or py37 venvs and run blue from the command line, either with --check or --diff it works.

Because the resulting coverage lines are different, my suspicion is that we need to monkey patch things differently for Python < 3.8, but I don't have any other ideas more than that.

I'm stalled, and I'm pretty tempted to get out of this by just dropping Python 3.6 and 3.8! What do you think @grantjenks

hauntsaninja commented 2 years ago

@warsaw I took a look following your mention of this issue and I think I figured it out. It's a fun one, the perfect storm of a couple things. Find me at pycon!

warsaw commented 2 years ago

@hauntsaninja Oh I can't wait! I have a thing this morning but I'll come find you afterward.

mcepl commented 2 years ago

Thank you.