Unexpected persistent variables in Workbench script window

Expected behavior

When I run a script it should start with a “clean” interpreter. Variables from the last run should not reappear unless they are set, and I should get a “name ‘x’ is not defined” error if I use a value before setting it, for example if I delete or comment out the line where it used to be set.

Actual behavior

Variables defined in the script are recycled, causing different behaviour if the script is re-run after editing, compared to loading it later into a fresh tab and running.
Also modules loaded in an earlier run of the script persist if I comment out the “include” line. reload(module) doesn’t work very well if I’ve just edited the module in another tab, the traceback text-of-offending-line refers to the new version while my script actually called an earlier one.

Steps to reproduce the behavior

Enter and run the following:

x=1
print (x)

and then comment out or delete the line “x=1” and run again.

Platforms affected

Mantid Workbench 4.1 on Windows, possibly others.

Thank you for finding this! An issue has been created: Workbench and Mantidplot remembers the values of variables after executing a script · Issue #27185 · mantidproject/mantid · GitHub

This bug has reappeared (in Mantid 5.0 or perhaps just recent nightly versions). Was a unit test added?

I don’t think this ever got fixed. I think solving this will be more complicated than it seems and getting the user experience to match what is expected may be difficult.
I’ve added this issue to our backlog so it will hopefully be looked at when we can.