-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
C: invalid codeBlack destroyed a valid Python fileBlack destroyed a valid Python fileF: fmtofffmt: off implementationfmt: off implementationT: bugSomething isn't workingSomething isn't working
Description
Describe the bug
I am getting an exception error: cannot format test_black.py: INTERNAL ERROR: Black produced code that is not equivalent to the source.
within a very specific scenario.
To Reproduce:
- Take this file 'test_black.py'
import pytest
class TestDummy:
# fmt: off
@pytest.mark.parametrize("param1", ["foo", "bar"]) # line A
# fmt: on
@pytest.mark.skip("special line") # line B
def test_dummy(self, param1):
print(param1)
print("if you remove me, it will work too") # line C
- Run Black on it
$ black test_black.py
- See error
error: cannot format test_black.py: INTERNAL ERROR: Black produced code that is not equivalent to the source. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful: /tmp/blk_s3rf0vdz.log
Oh no! 💥 💔 💥
1 file failed to reformat.
Expected behavior
The file is already well-formatted. I was expecting no error on the console.
Environment:
- Version: 21.5b1 or main
- OS and Python version: Linux with Python 3.8.5
- also on OS and Python version: macOS Darwin 19.6.0 with Python 3.8.0
Does this bug also happen on main?:
Yes, it happens.
Additional context
This file has a minimal setup to reproduce the error:
- if
# fmt: off
(above line with comment# line A
) is removed OR... - if the line with the comment
# line B
is removed (only for main and for macOS) OR... - if the line with comment
# line C
is removed
then Black run without any error.
Here is the attached log file:
blk_zpx9dsc4.log
Metadata
Metadata
Assignees
Labels
C: invalid codeBlack destroyed a valid Python fileBlack destroyed a valid Python fileF: fmtofffmt: off implementationfmt: off implementationT: bugSomething isn't workingSomething isn't working