diff --git a/ops/pebble.py b/ops/pebble.py index 614451944..cc2994231 100644 --- a/ops/pebble.py +++ b/ops/pebble.py @@ -3216,7 +3216,9 @@ def feed(self, data: bytes): self._parser.feed(data) def _prepare_tempfile(self, filename: str): - tf = tempfile.NamedTemporaryFile(delete=False) + # TODO: Remove noqa SIM115 when the following issue is fixed. + # https://github.com/astral-sh/ruff/issues/7313 + tf = tempfile.NamedTemporaryFile(delete=False) # noqa: SIM115 self._files[filename] = tf # type: ignore # we have a custom protocol for it self.current_filename = filename diff --git a/test/test_main.py b/test/test_main.py index 6aea9eed4..7628a33b5 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -1231,7 +1231,9 @@ def test_hook_and_dispatch_with_failing_hook( request: pytest.FixtureRequest, fake_script: FakeScript, ): - self.stdout = self.stderr = tempfile.TemporaryFile() + # TODO: Remove noqa SIM115 when the following issue is fixed. + # https://github.com/astral-sh/ruff/issues/7313 + self.stdout = self.stderr = tempfile.TemporaryFile() # noqa: SIM115 request.addfinalizer(self.stdout.close) fake_script_hooks = FakeScript(request, self.hooks_dir) @@ -1383,7 +1385,9 @@ def _call_event( @pytest.mark.usefixtures('setup_charm') def test_crash_action(self, request: pytest.FixtureRequest, fake_script: FakeScript): self._prepare_actions() - self.stderr = tempfile.TemporaryFile('w+t') + # TODO: Remove noqa SIM115 when the following issue is fixed. + # https://github.com/astral-sh/ruff/issues/7313 + self.stderr = tempfile.TemporaryFile('w+t') # noqa: SIM115 request.addfinalizer(self.stderr.close) fake_script.write('action-get', "echo '{}'") with pytest.raises(subprocess.CalledProcessError): diff --git a/test/test_model.py b/test/test_model.py index 7eb2ffafe..f4ec278d5 100644 --- a/test/test_model.py +++ b/test/test_model.py @@ -2808,7 +2808,9 @@ def test_relation_set_juju_version_quirks( version: str, ): # on 2.7.0+, things proceed as expected - t = tempfile.NamedTemporaryFile() + # TODO: Remove noqa SIM115 when the following issue is fixed. + # https://github.com/astral-sh/ruff/issues/7313 + t = tempfile.NamedTemporaryFile() # noqa: SIM115 try: fake_script.write( 'relation-set', diff --git a/test/test_pebble.py b/test/test_pebble.py index 004ddc6bb..56896f182 100644 --- a/test/test_pebble.py +++ b/test/test_pebble.py @@ -3691,9 +3691,11 @@ def test_wait_passed_output_bad_command( assert io_ws.sends == [] def test_wait_file_io(self, client: MockClient): - fin = tempfile.TemporaryFile(mode='w+', encoding='utf-8') - out = tempfile.TemporaryFile(mode='w+', encoding='utf-8') - err = tempfile.TemporaryFile(mode='w+', encoding='utf-8') + # TODO: Remove noqa SIM115 when the following issue is fixed. + # https://github.com/astral-sh/ruff/issues/7313 + fin = tempfile.TemporaryFile(mode='w+', encoding='utf-8') # noqa: SIM115 + out = tempfile.TemporaryFile(mode='w+', encoding='utf-8') # noqa: SIM115 + err = tempfile.TemporaryFile(mode='w+', encoding='utf-8') # noqa: SIM115 try: fin.write('foo\n') fin.seek(0) diff --git a/test/test_storage.py b/test/test_storage.py index 2df43df1d..c03586c4f 100644 --- a/test/test_storage.py +++ b/test/test_storage.py @@ -441,7 +441,9 @@ def test_is_available(self, fake_script: FakeScript): assert fake_script.calls(clear=True) == [] def test_set_encodes_args(self, fake_script: FakeScript): - t = tempfile.NamedTemporaryFile() + # TODO: Remove noqa SIM115 when the following issue is fixed. + # https://github.com/astral-sh/ruff/issues/7313 + t = tempfile.NamedTemporaryFile() # noqa: SIM115 try: fake_script.write( 'state-set', @@ -478,7 +480,9 @@ def test_get(self, fake_script: FakeScript): ] def test_set_and_get_complex_value(self, fake_script: FakeScript): - t = tempfile.NamedTemporaryFile() + # TODO: Remove noqa SIM115 when the following issue is fixed. + # https://github.com/astral-sh/ruff/issues/7313 + t = tempfile.NamedTemporaryFile() # noqa: SIM115 try: fake_script.write( 'state-set',