Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suppress pylint warn contextmanager-generator-missing-cleanup #3138

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/ci_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,15 @@ jobs:
# * On 3.9 pylint crashes when parsing azurelinuxagent/daemon/main.py (see https://github.com/pylint-dev/pylint/issues/9473), so we ignore it.
# * 'no-self-use' ("R0201: Method could be a function") was moved to an optional extension on 3.8 and is no longer used by default. It needs
# to be suppressed for previous versions (3.0-3.7), though.
#
# * 'contextmanager-generator-missing-cleanup' are false positives if yield is used inside an if-else block for contextmanager generator functions.
# (https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/contextmanager-generator-missing-cleanup.html).
# This is not implemented on versions (3.0-3.7) Bad option value 'contextmanager-generator-missing-cleanup' (bad-option-value)
PYLINT_OPTIONS="--rcfile=ci/pylintrc --jobs=0"
if [[ "${{ matrix.python-version }}" == "3.5" ]]; then
PYLINT_OPTIONS="$PYLINT_OPTIONS --disable=bad-option-value"
fi
if [[ "${{ matrix.python-version }}" == "3.9" ]]; then
PYLINT_OPTIONS="$PYLINT_OPTIONS --disable=no-member --ignore=main.py"
fi
if [[ "${{ matrix.python-version }}" =~ ^3\.[0-7]$ ]]; then
PYLINT_OPTIONS="$PYLINT_OPTIONS --disable=no-self-use"
PYLINT_OPTIONS="$PYLINT_OPTIONS --disable=no-self-use,bad-option-value"
fi

echo "PYLINT_OPTIONS: $PYLINT_OPTIONS"
Expand Down
6 changes: 4 additions & 2 deletions tests/ga/test_multi_config_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ def __setup_generic_test_env(self):
third_ext = extension_emulator(name="OSTCExtensions.ExampleHandlerLinux.thirdExtension")
fourth_ext = extension_emulator(name="Microsoft.Powershell.ExampleExtension")

with self._setup_test_env(mock_manifest=True) as (exthandlers_handler, protocol, no_of_extensions):
# In _setup_test_env() contextmanager, yield is used inside an if-else block and that's creating a false positive pylint warning
with self._setup_test_env(mock_manifest=True) as (exthandlers_handler, protocol, no_of_extensions): # pylint: disable=contextmanager-generator-missing-cleanup
with enable_invocations(first_ext, second_ext, third_ext, fourth_ext) as invocation_record:
exthandlers_handler.run()
exthandlers_handler.report_ext_handlers_status()
Expand Down Expand Up @@ -1070,7 +1071,8 @@ def __setup_test_and_get_exts(self):
dependent_sc_ext = extension_emulator(name="Microsoft.Powershell.ExampleExtension")
independent_sc_ext = extension_emulator(name="Microsoft.Azure.Geneva.GenevaMonitoring", version="1.1.0")

with self._setup_test_env() as (exthandlers_handler, protocol, no_of_extensions):
# In _setup_test_env() contextmanager, yield is used inside an if-else block and that's creating a false positive pylint warning
with self._setup_test_env() as (exthandlers_handler, protocol, no_of_extensions): # pylint: disable=contextmanager-generator-missing-cleanup
yield exthandlers_handler, protocol, no_of_extensions, first_ext, second_ext, third_ext, dependent_sc_ext, independent_sc_ext

def test_it_should_process_dependency_chain_extensions_properly(self):
Expand Down
7 changes: 4 additions & 3 deletions tests/ga/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,8 @@ def test_it_should_not_set_dns_tcp_iptable_if_drop_and_accept_available(self):
@contextlib.contextmanager
def _setup_test_for_ext_event_dirs_retention(self):
try:
with _get_update_handler(test_data=DATA_FILE_MULTIPLE_EXT, autoupdate_enabled=False) as (update_handler, protocol):
# In _get_update_handler() contextmanager, yield is used inside an if-else block and that's creating a false positive pylint warning
with _get_update_handler(test_data=DATA_FILE_MULTIPLE_EXT, autoupdate_enabled=False) as (update_handler, protocol): # pylint: disable=contextmanager-generator-missing-cleanup
with patch("azurelinuxagent.common.agent_supported_feature._ETPFeature.is_supported", True):
update_handler.run(debug=True)
expected_events_dirs = glob.glob(os.path.join(conf.get_ext_log_dir(), "*", EVENTS_DIRECTORY))
Expand Down Expand Up @@ -1483,8 +1484,8 @@ def __get_update_handler(self, iterations=1, test_data=None,
reload_conf=None, autoupdate_frequency=0.001, hotfix_frequency=1.0, normal_frequency=2.0):

test_data = DATA_FILE if test_data is None else test_data

with _get_update_handler(iterations, test_data) as (update_handler, protocol):
# In _get_update_handler() contextmanager, yield is used inside an if-else block and that's creating a false positive pylint warning
with _get_update_handler(iterations, test_data) as (update_handler, protocol): # pylint: disable=contextmanager-generator-missing-cleanup

protocol.aggregate_status = None

Expand Down
Loading