psf / black

The uncompromising Python code formatter
https://black.readthedocs.io/en/stable/
MIT License
38.76k stars 2.44k forks source link

hide stderr of blackd during test runs #598

Closed BeyondEvil closed 5 years ago

BeyondEvil commented 5 years ago

Howdy! Sorry you're having trouble. To expedite your experience, provide some basics for me:

Operating system: osx 10.12.6 Python version: 3.7.0 (brew installed) Pipenv version: 2018.10.13 (brew installed) Black version: master Does also happen on master: yes

Followed the guide in CONTRIBUTING.md, after forking and git cloning, eg:

  1. pipenv install --dev (I also do --skip-lock)
  2. pre-commit install

For sanity, I also ran pipenv run python setup.py test before making any changes, and one test failed:

test_black (tests.test_black.BlackTestCase) ... ok
test_blackd_fast (tests.test_black.BlackTestCase) ... /Users/jimbrannlund/.local/share/virtualenvs/black-KDUbt9_N/lib/python3.7/site-packages/aiohttp/web_urldispatcher.py:114: DeprecationWarning: Bare functions are deprecated, use async ones
  "use async ones", DeprecationWarning)
ERROR:root:Exception during handling a request
concurrent.futures.process._RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/Users/jimbrannlund/dev/black/black.py", line 3292, in assert_equivalent
    src_ast = ast.parse(src)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    ur'hello'
            ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/process.py", line 232, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "/Users/jimbrannlund/dev/black/black.py", line 616, in format_file_contents
    assert_equivalent(src_contents, dst_contents)
  File "/Users/jimbrannlund/dev/black/black.py", line 3296, in assert_equivalent
    f"cannot use --safe with this file; failed to parse source file "
AssertionError: cannot use --safe with this file; failed to parse source file with Python 3.7's builtin AST. Re-run with --fast or stop using deprecated Python 2 syntax. AST error message: invalid syntax (<unknown>, line 1)
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/jimbrannlund/dev/black/blackd.py", line 96, in handle
    mode=mode,
AssertionError: cannot use --safe with this file; failed to parse source file with Python 3.7's builtin AST. Re-run with --fast or stop using deprecated Python 2 syntax. AST error message: invalid syntax (<unknown>, line 1)
ok
test_blackd_invalid_line_length (tests.test_black.BlackTestCase) ... ok
zsol commented 5 years ago

That test is actually passing (it's testing the behavior of blackd when fed invalid input).

BeyondEvil commented 5 years ago

Ah, I see... I guess I should've read the output more thoroughly.

This fooled me:

Ran 88 tests in 14.411s

FAILED (failures=1)
Test failed: <unittest.runner.TextTestResult run=88 errors=0 failures=1>
error: Test failed: <unittest.runner.TextTestResult run=88 errors=0 failures=1>

I saw the output and what looked like a legit stacktrace and just assumed that was it. Turned out it was another test that failed:


What to do @zsol ?
FAIL: test_expression_diff (tests.test_black.BlackTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jimbrannlund/dev/black/tests/test_black.py", line 294, in test_expression_diff
    self.assertEqual(expected, actual, msg)
AssertionError: '--- [Deterministic header]\n+++ [Deterministi[13757 chars]ER\n' != '--- /var/folders/8g/g0s3c_xn0d793245v_mj5khm0[13827 chars]ER\n'
- --- [Deterministic header]
+ --- /var/folders/8g/g0s3c_xn0d793245v_mj5khm0000gn/T/blk_kg99939c.log 2018-11-07 15:36:27 +0000
  +++ [Deterministic header]
  @@ -1,8 +1,8 @@

**SNIP WALL OF OUTPUT**

   # standalone comment at ENDMARKER
 : Expected diff isn't equal to the actual. If you made changes to expression.py and this is an anticipated difference, overwrite tests/expression.diff with /var/folders/8g/g0s3c_xn0d793245v_mj5khm0000gn/T/blk_lsa5erii.log

Edit: I have a PR ready to send stderr to Beelzebub for that test (test_blackd_fast). But I need some guidance on what to do with the test_expression_diff failure.

BeyondEvil commented 5 years ago

Y'all are making hard for me to contribute.

Tried committing "silence stderr", but I don't have 3.6, I have 3.7.

(black) bash-3.2$ git commit -a -m "Silence expected stderr output during test"
black....................................................................Passed
flake8...................................................................Failed
hookid: flake8

tests/test_black.py:1:1: T499 usage: mypy [-h] [-v] [-V] [more options; see below]
tests/test_black.py:2:1: T499             [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
tests/test_black.py:3:1: T499 mypy: error: failed to find a Python executable matching version (3, 6), perhaps try --python-executable, or --no-site-packages?

mypy.....................................................................Passed
BeyondEvil commented 5 years ago

ping @zsol

zsol commented 5 years ago

Hey @BeyondEvil looks like flake8-mypy is hardcoding python 3.6. Until we get this fixed, you have two options to work it around: