Forum Discussion
It would help if you provide your Python script to look at.
Root Cause Analysis
TestComplete’s Python engine loads each script unit only once per project session. Any references you make to ProjectSuite.Variables, Project.Variables or Log.Message at the module (global) scope execute at import time—and then stay cached.
- On first run, the module is imported, the global references succeed, and everything works.
- On subsequent runs, TestComplete reuses the already-loaded module and does not re-evaluate module-level code. Your stale or missing references now trigger “object not found.”
- Likewise, calling Log.Message outside of a test routine or after import can silently fail or not bind to the TestComplete test engine context.
Step-by-Step Solution
- Move all variable reads and log calls inside a Python function or test routine—never at the top-level of the script unit.
- Use the full object model for each variable kind:
- Suite variables: ProjectSuite.Variables.YourSuiteVar
- Project variables: Project.Variables.YourProjectVar
- Keyword-test variables: pass them as parameters when you invoke your Python routine from a Keyword Test.
- Inside your routine, wrap your variable lookups in a try/except to catch missing-object errors and report them via Log.Error().
- Ensure you invoke your function from a Python Script Test or call it via a Keyword Test each time you need it. This guarantees the code block that reads variables and logs runs fresh on every execution.
- (Optional) If you ever need to force-reload your module after editing, you can use Python’s importlib.reload(), but well-structured functions typically make that unnecessary.
Code Snippet
With this pattern, every time you run the Test routine—whether back-to-back or after many runs—the engine will (re)execute ReadAndLogVariables(), freshly resolve your variables, and correctly bind Log.Message() to the active test context.
# Put this in your Script Unit, not at module top-level
def ReadAndLogVariables():
# Dynamically fetch suite & project variables
try:
suite_var = ProjectSuite.Variables.MySuiteVariable
project_var = Project.Variables.MyProjectVariable
except AttributeError as e:
Log.Error("Variable access failed: " + str(e))
return
# Log the values so you can verify each run
Log.Message("Suite variable value: {}".format(suite_var))
Log.Message("Project variable value: {}".format(project_var))
# Your Python Script Test entry point
def Test():
ReadAndLogVariables()
💬 If a response helped you out, don’t forget to Like it! And if it answered your question, mark it as the solution so others can benefit too.
Note: This reply was drafted with AI assistance, and as I do not have access to license I did not try out such Code Snippet.