Whole file

GoogleCloudPlatform/terraform-python-testing-helper

The author described this change as Fix TypeError when calling decorated methods with positional arguments (#93). It counts as a record because the check below fails on the code as it stood at f1332cc8b and passes on f8c79b4b8, with nothing else changed between the two runs.

Fix saved2026-06-29
Sharing licenceApache-2.0 · LICENSE
Change size+13 8

What the code was meant to do, written into the code itself as a save note

Fix TypeError when calling decorated methods with positional arguments (#93)

The change

3636 from pathlib import Path
3737 from typing import Any, Dict, List, Optional, Union
3838
39-__version__ = '1.8.6'
39+__version__ = '1.8.8'
4040
4141 _LOGGER = logging.getLogger('tftest')
4242
411411 default=str).encode("cp037")).hexdigest() + ".pickle"
412412
413413 def _cache(func):
414+ sig = inspect.signature(func)
414415
415- def cache(self, **kwargs):
416+ def cache(self, *args, **kwargs):
416417 """
417418 Runs the tftest instance method or retreives the cache value if it exists
418419
424425 _LOGGER.info("Cache decorated method: %s", func.__name__)
425426
426427 if not self.enable_cache:
427- return func(self, **kwargs)
428- elif not kwargs.get("use_cache", False):
429- return func(self, **kwargs)
428+ return func(self, *args, **kwargs)
430429
430+ method_args = sig.bind(self, *args, **kwargs).arguments
431+ method_args.pop('self', None)
432+
433+ if not method_args.get("use_cache", False):
434+ return func(self, *args, **kwargs)
435+
431436 cache_dir = self.cache_dir / \
432437 Path(sha1(str(self.tfdir).encode("cp037")).hexdigest()) / \
433438 Path(func.__name__)
434439 cache_dir.mkdir(parents=True, exist_ok=True)
435440
436- hash_filename = self.generate_cache_hash(kwargs)
441+ hash_filename = self.generate_cache_hash(method_args)
437442 cache_key = cache_dir / hash_filename
438443 _LOGGER.debug("Cache key: %s", cache_key)
439444
446451 return pickle.load(f)
447452
448453 _LOGGER.info("Running command")
449- out = func(self, **kwargs)
454+ out = func(self, *args, **kwargs)
450455
451456 if out:
452457 # the hash value will now include any changes
453458 # to the tfdir directory
454- hash_filename = self.generate_cache_hash(kwargs)
459+ hash_filename = self.generate_cache_hash(method_args)
455460 cache_key = cache_dir / hash_filename
456461 _LOGGER.debug("Cache key: %s", cache_key)
457462

The check that tells the two apart

failpass·test/test_cache.py::test_output_positional_arg[True]

Check file test/test_cache.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itf1332cc8bf424fb4240bc7e0a122c5fb8d616262
Broken version dated2026-03-31
Moduletftest
Units changedTerraformTest
Fingerprint2786d3812ae3972f
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in GoogleCloudPlatform/terraform-python-testing-helper