From patchwork Sat Mar 14 23:16:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1984 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530270; bh=obnkSMkfO1BVS57pYMJuPo14sHjbw6yZayoL8+NEDoo=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=FGFwpBOvEi3TosdChQ31Fo2WE4BKARChQDCKLDoTvILB+21rbTrUVXeO4hJ6IQmXe 8aSEfFzW5QWiz2TwbSV+gU9Y2uufxTxBBtSPklTMORyS0GWswbAL/fR8vKSUVFTqqY 8JB6zuMt1eRvDuRJxmAcwUOFO2kL+eqsxrU7SVUAkokqVKh7yNENFRR4UCCZJLqu0q bYuqebQfI7yhmw4OuS7Kypldbl5pvCKOor5+dWDV0dieKbwvDQnPH/GF3CiG2+55CF lSK34fA1a4MsHcVB2YX1M9Ly64jGAi+Kuh8wbD0U4jyH/l+rprWOzQ9/2vyd2pWL0+ efdedkJyl4lNw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 98C5B6A04C for ; Sat, 14 Mar 2026 17:17:50 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id D6TCzGzYW7Dg for ; Sat, 14 Mar 2026 17:17:50 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530268; bh=obnkSMkfO1BVS57pYMJuPo14sHjbw6yZayoL8+NEDoo=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=rutjwI/baJvbLNCO0QGcZqbXSp/TqJbo9gIuc/TwS6dCaNizCy/PYCJN7SqKTgaVt z/x6x+S+QU+g4tdTtKjnBSC5ox0u0evK0Rkr2LhfrpgUbwFL4q5bfJzEt5kR2u1okI KTIz3L0n7QXfrbw2moR4J8Bc/vlKUULUSxfLuHWOuyIhSmJCVOQzhIhq1pQstfI07V nRNjrPDqPQDq6yk/4gmEhYcs77wQFvk7KL7/HJ60gnN1ITe1HqHdzwrnUKb4dZavn5 wi8JjfnOsIZ9CC8Gosh64C6v7D5IZ++e0cLactMt2lzhzb9O/NSYSqPV3fwcWvTRkr XClNR/rZj9iBw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CC1996A038 for ; Sat, 14 Mar 2026 17:17:48 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530264; bh=bLw1rihpM5Q90hz3dXziDB37vYqUc515kQ+gfjFAyUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DnqQRdRclK7oLL89/VixVY7wmG4BYSnP4vlvNREELTeJUNurT2B/fEmseI8Hujirx iY7SMNtTWHtIPBY7sviDZa5S4g/liTuZMq3RR6bVKjkKfSfnZMH/4c3VYky5l0oiXb PoseNuWpJNQ8/HDq1AVq/hh+nfEjhUEoe4ECLrwzMgD+T0whVnaVknR94o2Ur7TFYw yspj53uq+m1g41KEjxOZ5B38LA497bz8Q2Kx7zpzgfZWDGgpuhwMtUbMfpHK7wJ0Z0 kVvnB9zMY8Ae0eDJd2qHxSoO0Gef/rj+Hq1BD4xAqLwhP09Nr6vqx6JPi6ztZIgmCL 1WfjRV82/dBXA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 17A3A6A03D; Sat, 14 Mar 2026 17:17:44 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id nev4IWPuH8Yq; Sat, 14 Mar 2026 17:17:44 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530260; bh=sNdVeoQwkvTsBYaKBBTeJed0pZWGfa+DJcXdSEzHBhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XMlZ5l7xp8+GbP4msWsytU0JZqmapfO2nU2pRjVW+LLwEuBgQTkfJ3IbUGLoGaoNF g7nxnsAA5k+UOrBmX9ME2/Yku3hWo65zpfIZucDqQyYV2bXVhgEYLrcprFJT11Q9eN t5bZECDvMFX0mpNgERWQ/zsgZVCB1HfscYVhaCgIy9Q2yJCqvai3OoPpekpsInnS33 lxn3osaSwi3RPkduY9OyN9c/c42d41RWCMQrGA42h5x7l442IAoSauFWxnh+PMZEGF 4KnKSi0uzZqx1DIucxhwbTn+wn9HM/Dm48l39302vus1jlO/joPfoTB1cyHh2qcN5w W6mEVrSIIQuOQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id CCE3C6A03A; Sat, 14 Mar 2026 17:17:39 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Sat, 14 Mar 2026 17:16:01 -0600 Message-ID: <20260314231618.338113-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260314231618.338113-1-sjg@u-boot.org> References: <20260314231618.338113-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 5TMBCD5PBJ7SXAFF6EAIWVCYRAFH7RLY X-Message-ID-Hash: 5TMBCD5PBJ7SXAFF6EAIWVCYRAFH7RLY X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 10/19] test: py: Fix PersistentFileHelperCtxMgr with stale .pyc List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass inspect.getmodule() returns None when the .pyc file is compiled with a different source path, e.g. when running tests inside a container after building outside it, or vice versa. This causes an AttributeError on module.__file__ in PersistentFileHelperCtxMgr Fall back to the caller's filename from the stack frame when the module cannot be resolved. Signed-off-by: Simon Glass --- test/py/utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/py/utils.py b/test/py/utils.py index 7812b2a201b..083a3feddc2 100644 --- a/test/py/utils.py +++ b/test/py/utils.py @@ -303,8 +303,17 @@ class PersistentFileHelperCtxMgr(object): def __enter__(self): frame = inspect.stack()[1] module = inspect.getmodule(frame[0]) - self.module_filename = module.__file__ - self.module_timestamp = os.path.getmtime(self.module_filename) + if module is not None: + self.module_filename = module.__file__ + else: + self.module_filename = frame[1] + + if os.path.exists(self.module_filename): + self.module_timestamp = os.path.getmtime(self.module_filename) + else: + # The .pyc was compiled with a different source path + # (e.g. inside/outside a container). Skip staleness check. + self.module_timestamp = 0 if os.path.exists(self.filename): filename_timestamp = os.path.getmtime(self.filename)