From baa1a4cd442393b7d420913fec619ddecc2f25a7 Mon Sep 17 00:00:00 2001 From: hanjinpeng Date: Sun, 13 Sep 2026 21:49:04 -0400 Subject: [PATCH] tests: do not depend on CPython's 'test' package test_compat.py imported 'test.support' only to locate the 'cfgparser.1' data file shipped with CPython's own test suite. That package is not installed on many systems (it is packaged separately, e.g. python3-test on Fedora/CentOS), so the whole module failed to import: ModuleNotFoundError: No module named 'test' and 'python3 -m pytest' aborted during collection. Create the needed file in a temporary directory instead, and drop python3-test from the CI pre-test script. Fixes: https://github.com/candlepin/python-iniparse/issues/28 --- scripts/container-pre-test.sh | 5 ++--- tests/test_compat.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/container-pre-test.sh b/scripts/container-pre-test.sh index 7c6a407..ea8c9ae 100644 --- a/scripts/container-pre-test.sh +++ b/scripts/container-pre-test.sh @@ -1,10 +1,9 @@ #!/bin/bash source /etc/os-release -# This repository is required for python3-pytest and python3-test -# on Centos Stream +# This repository is required for python3-pytest on Centos Stream if [[ $ID == "centos" ]]; then dnf config-manager --enable crb fi -dnf install -y python3-setuptools python3-pip python3-devel python3-pytest python3-test +dnf install -y python3-setuptools python3-pip python3-devel python3-pytest diff --git a/tests/test_compat.py b/tests/test_compat.py index 611e743..cc4fad4 100644 --- a/tests/test_compat.py +++ b/tests/test_compat.py @@ -10,6 +10,8 @@ """ import os +import shutil +import tempfile from iniparse import compat as ConfigParser from io import StringIO try: @@ -18,8 +20,6 @@ import collections as UserDict import unittest -from test import support as test_support - class SortedDict(UserDict.UserDict): def items(self): @@ -466,9 +466,13 @@ def test_read_returns_file_list(self): 3. Empty list is returned due to file not existing. 4. Empty list is returned since no files were passed. """ - file1 = test_support.findfile("cfgparser.1") - if not os.path.exists(file1): - file1 = test_support.findfile("configdata/cfgparser.1") + # Do not depend on the data files of CPython's 'test' package, + # which is not installed on many systems. + tmpdir = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, tmpdir) + file1 = os.path.join(tmpdir, "cfgparser.1") + with open(file1, "w") as f: + f.write("[Foo Bar]\nfoo=newbar\n") # check when we pass a mix of readable and non-readable files: cf = self.newconfig() parsed_files = cf.read([file1, "nonexistant-file"])