diff --git a/tests/unit/test_isort.py b/tests/unit/test_isort.py index c241e325..71681a2f 100644 --- a/tests/unit/test_isort.py +++ b/tests/unit/test_isort.py @@ -5562,6 +5562,21 @@ def seekable(self): assert identified_imports == [":1 import m2", ":2 import m1"] +def test_unindented_comments_issue_1899(): + """Ensure unindented comments in indented blocks are handled correctly""" + + test_input = """ +import sys + +if True: +# this comment will get cut off + import os + + """ + + assert isort.code(test_input) == test_input + + def test_split_on_trailing_comma() -> None: test_input = "from lib import (a, b, c,)" expected_output = """from lib import (