From 838107e89bc38477ac6bdbac0da0d6359fd1c865 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Sun, 6 Oct 2024 09:54:45 +0200 Subject: [PATCH] make test more reliable on win --- psutil/tests/__init__.py | 1 + psutil/tests/test_testutils.py | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index d3ea5f381..dd31392c0 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -939,6 +939,7 @@ def main(*args, **kw): # noqa ARG004 UserWarning, stacklevel=1, ) + return suite @staticmethod def raises(exc, match=None): diff --git a/psutil/tests/test_testutils.py b/psutil/tests/test_testutils.py index c20745e90..7293aa010 100755 --- a/psutil/tests/test_testutils.py +++ b/psutil/tests/test_testutils.py @@ -486,20 +486,18 @@ def test_main(self): pass with open(os.path.join(tmpdir, "test_file.py"), "w") as f: f.write(textwrap.dedent("""\ - import unittest, os + import unittest class TestCase(unittest.TestCase): - def test_foo(self): - path = os.path.join("{}", "hello.txt") - with open(path, "w") as f: - pass - """.format(tmpdir)).lstrip()) + def test_passed(self): + pass + """).lstrip()) with mock.patch.object(psutil.tests, "HERE", tmpdir): with self.assertWarnsRegex( UserWarning, "Fake pytest module was used" ): - fake_pytest.main() - call_until(lambda: os.path.isfile(os.path.join(tmpdir, "hello.txt"))) + suite = fake_pytest.main() + assert suite.countTestCases() == 1 def test_warns(self): # success