diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2021-04-12 17:16:44 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-04-13 22:41:10 +0000 |
commit | 719b551566e359712e674fef43d52e963f90d07a (patch) | |
tree | 2d6d32bf59b97b3e48eb53f3d39cac79a5b3c002 /zephyr/zmake/zmake/zmake.py | |
parent | 8bbececa9a763803ecaf4169919bb9cca22eb558 (diff) | |
download | chrome-ec-719b551566e359712e674fef43d52e963f90d07a.tar.gz |
zephyr: zmake: bind lambda for pytest using default argument
In Python, a lambda or function will capture variables in the parent
scope, but using a variable in a loop does not create a new scope.
Thus, the test_file argument is being executed as the current value of
test_file, not necessarily the value that happened that iteration in
the loop.
Prior to this CL, we were not guaranteed to run every pytest. It's
racy and causes us to run some tests twice or even three times, while
completely skipping other tests.
Using a default argument in the lambda will bind to the current value
instead of the variable.
See this SO post for further discussion:
https://stackoverflow.com/questions/2295290
BUG=none
BRANCH=none
TEST=zmake testall
Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Change-Id: I5eda075980cce0af13fb7a114fd1917fa6732754
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2823148
Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'zephyr/zmake/zmake/zmake.py')
-rw-r--r-- | zephyr/zmake/zmake/zmake.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/zephyr/zmake/zmake/zmake.py b/zephyr/zmake/zmake/zmake.py index 307ed7a6b1..13b113af02 100644 --- a/zephyr/zmake/zmake/zmake.py +++ b/zephyr/zmake/zmake/zmake.py @@ -417,7 +417,7 @@ class Zmake: return rv for test_file in directory.glob('test_*.py'): - self.executor.append(func=lambda: run_test(test_file)) + self.executor.append(func=lambda f=test_file: run_test(f)) def testall(self): """Test all the valid test targets""" |