commit:     f027096346460cb031c2cb6c66e494b79d1b4433
Author:     David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri May  5 15:38:54 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 26 15:44:37 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=f0270963

tests: process: port to pytest test about spawning with large env var

Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/tests/process/test_spawn_fail_e2big.py | 50 +++++++++-------------
 1 file changed, 20 insertions(+), 30 deletions(-)

diff --git a/lib/portage/tests/process/test_spawn_fail_e2big.py 
b/lib/portage/tests/process/test_spawn_fail_e2big.py
index d3be51670..7a0096630 100644
--- a/lib/portage/tests/process/test_spawn_fail_e2big.py
+++ b/lib/portage/tests/process/test_spawn_fail_e2big.py
@@ -2,39 +2,29 @@
 # Distributed under the terms of the GNU General Public License v2
 
 import platform
-import tempfile
 
-from pathlib import Path
+import pytest
 
 import portage.process
-
-from portage import shutil
 from portage.const import BASH_BINARY
-from portage.tests import TestCase
-
-
-class SpawnE2bigTestCase(TestCase):
-    def testSpawnE2big(self):
-        if platform.system() != "Linux":
-            self.skipTest("not Linux")
-
-        env = dict()
-        env["VERY_LARGE_ENV_VAR"] = "X" * 1024 * 256
 
-        tmpdir = tempfile.mkdtemp()
-        try:
-            logfile = tmpdir / Path("logfile")
-            echo_output = "Should never appear"
-            retval = portage.process.spawn(
-                [BASH_BINARY, "-c", "echo", echo_output], env=env, 
logfile=logfile
-            )
 
-            with open(logfile) as f:
-                logfile_content = f.read()
-                self.assertIn(
-                    "Largest environment variable: VERY_LARGE_ENV_VAR (262164 
bytes)",
-                    logfile_content,
-                )
-            self.assertEqual(retval, 1)
-        finally:
-            shutil.rmtree(tmpdir)
[email protected](platform.system() != "Linux", reason="not Linux")
+def test_spawnE2big(capsys, tmp_path):
+    env = dict()
+    env["VERY_LARGE_ENV_VAR"] = "X" * 1024 * 256
+
+    logfile = tmp_path / "logfile"
+    echo_output = "Should never appear"
+    with capsys.disabled():
+        retval = portage.process.spawn(
+            [BASH_BINARY, "-c", "echo", echo_output], env=env, logfile=logfile
+        )
+
+    with open(logfile) as f:
+        logfile_content = f.read()
+        assert (
+            "Largest environment variable: VERY_LARGE_ENV_VAR (262164 bytes)"
+            in logfile_content
+        )
+    assert retval == 1

Reply via email to