From ef172efc3cde1697b2a311ac415aeae732b8eb88 Mon Sep 17 00:00:00 2001 From: Aniruddha Date: Tue, 1 Mar 2022 17:02:21 +0530 Subject: [PATCH] Add failing test for unindenred comment --- tests/unit/test_isort.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/unit/test_isort.py b/tests/unit/test_isort.py index 293b99bec..ffa01b66f 100644 --- a/tests/unit/test_isort.py +++ b/tests/unit/test_isort.py @@ -5562,3 +5562,18 @@ def seekable(self): test_input = NonSeekableTestStream("import m2\n" "import m1\n" "not_import = 7") identified_imports = list(map(str, api.find_imports_in_stream(test_input))) 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