[英]VSCode Python region doesn't work in all cases
我正在使用 VSCode 編寫 Python 代碼。 我想使用#region foo
和#endregion foo
來提供自定義折疊。 這有時有效。 當我說有時我的意思是它適用於某些情況但不適用於其他情況。
import pytest
from unittest.mock import Mock
def test_advanced_function_call_count(myfile, monkeypatch, mocker):
# region setup
monkeypatch.setattr(myfile, 'basic_function', Mock())
# endregion setup
# region execution
myfile.advanced_function2()
assert myfile.basic_function.call_count == 1
# endregion execution
在上面的例子中,我可以折疊# region setup
但我不能折疊# region execution
。 在我的真實代碼中,似乎沒有只折疊一個區域、第一個區域或最后一個區域的模式。 它似乎是隨機的。
有什么想法阻止隨機區域折疊?
根據github中的這個頁面。
這應該是由重疊的折疊區域引起的( def
本身有一個隱藏的折疊)。 以您的代碼為例:
def test_advanced_function_call_count(myfile, monkeypatch, mocker): #region A start
# region setup #region B start
monkeypatch.setattr(myfile, 'basic_function', Mock())
# endregion setup #region B end
# region execution #region C start
myfile.advanced_function2()
assert myfile.basic_function.call_count == 1 #region A end
# endregion execution #region C end
可以允許區域 A 和區域 B 的包含關系:
# Range A start
# Range B start
# Range B end
# Range A end
我發現如果 # endregion 在 def 中的最后一行代碼之后,那么它是無效的。
但是A和C之間存在交錯包含關系,導致C折疊失敗:
# Range A start
# Range C start
# Range A end
# Range C end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.