You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Resource files should be re-processed when imported #2099
If I got it right, you are running a test suite that modifies the resource
file. I think that is not possible (not even desirable). When running
pybot, it creates a copy of all files to a temporary space and runs from
there.
On Wed, Aug 12, 2015 at 10:40 AM, dangdang03 [email protected]
wrote:
test procedure:
import resouce 1.txt -------first time
...
do some changes for resouce file(1.txt)
...
import resouce 1.txt ------- second time
for the second time, the import resouce file could not update the changes
to robot execution.
—
Reply to this email directly or view it on GitHub #2099.
@HelioGuilherme66 is correct that this doesn't work because resource files are actually processed only once. They aren't copied anywhere, though, but kept in a cache in memory. It would be possible to check has the file changed on the disk before reading information from the cache, but I'm not sure is that worth the effort.
I think that libraries and variable files work this way too, but I need to test that. With libraries a similar issue was solved by introducing Reload Library keyword in RF 2.9 (#293). In that case the motivation wasn't updating library source code, but libraries themselves getting more keywords dynamically.
Could you @dangdang03 explain your underlying use cases a bit more? Is there a reason you couldn't create new resource files instead of manipulating already imported resources?
After thinking about this a bit more, I believe it would be better to just not cache anything. The main reasons are the following:
Importing and processing libraries and resources is so fast that I doubt caching actually saves much time. Does execution get slower if we remove cache should be measured. There could be problems with very big resource files implemented in HTML format.
Cache spends memory. This is especially problematic with libs/resources that are only imported once. How much memory is saved if cache is removed should be measured.
changed the title [-]import resource with the same resouce file two times, the second time could not update resouce context changes when some changes on resouce file[/-][+]Resource files should be re-processed when imported[/+]on Aug 14, 2015
@pekkaklarck, sorry for later reply!
In my use cases, I expected to create the keyword automatedly during case execution, and the keywords context may be different every time, so I expected the import resource refreshed.
and I find lib code has provide this interface.
use cache when imported with Resource KW in *** Settings ***?
optionally use cache when imported with BuiltIn.Import Resource KW (e.g. with force_reimport=False arg?
how should the variable value overwriting behave in this case?
3.a) if a variable is already imported from the same resource file e.g. var_a = foo in my_resource_a.robot
a KW updates to var_a = bar my_resource_a.robot is imported again with var_a = foo
--> what should be the value of var_afoo or bar?
3.b) if a variable is already imported from another resource file e.g. my_resource_B.robot is imported with var_a = bar my_resource_a.robot is imported with var_a = foo
--> what should be the value of var_afoo or bar?
I use resource files quite often for "overriding default values" i.e.
my_test_suite.robot imports test_vars_resource.robot (e.g. var_a = bar) and some_KWs_resource.robot
some_KWs_resource.robot imports default_vars.robot (e.g. var_a = foo)
--> in these cases overriding var_a value would be highly undesired
I recently faced this same issue with RF 3.2.2, while trying to reload my variables.py-file for each test case.
The reload functionality would be really handy in the Import Variables-keyword, but as it does not support it currently, I came up with a workaround which I run in each test cases setup:
Activity
HelioGuilherme66 commentedon Aug 12, 2015
If I got it right, you are running a test suite that modifies the resource
file. I think that is not possible (not even desirable). When running
pybot, it creates a copy of all files to a temporary space and runs from
there.
On Wed, Aug 12, 2015 at 10:40 AM, dangdang03 [email protected]
wrote:
pekkaklarck commentedon Aug 12, 2015
@HelioGuilherme66 is correct that this doesn't work because resource files are actually processed only once. They aren't copied anywhere, though, but kept in a cache in memory. It would be possible to check has the file changed on the disk before reading information from the cache, but I'm not sure is that worth the effort.
I think that libraries and variable files work this way too, but I need to test that. With libraries a similar issue was solved by introducing
Reload Librarykeyword in RF 2.9 (#293). In that case the motivation wasn't updating library source code, but libraries themselves getting more keywords dynamically.Could you @dangdang03 explain your underlying use cases a bit more? Is there a reason you couldn't create new resource files instead of manipulating already imported resources?
pekkaklarck commentedon Aug 14, 2015
After thinking about this a bit more, I believe it would be better to just not cache anything. The main reasons are the following:
sys.modules. See Variable files should always be re-imported #2101 about issue suggesting that we should also ignoresys.modules.[-]import resource with the same resouce file two times, the second time could not update resouce context changes when some changes on resouce file[/-][+]Resource files should be re-processed when imported[/+]dangdang03 commentedon Aug 19, 2015
@pekkaklarck, sorry for later reply!
In my use cases, I expected to create the keyword automatedly during case execution, and the keywords context may be different every time, so I expected the import resource refreshed.
and I find lib code has provide this interface.
for the keywords lib as bellow:
but this interface is not open for user, the default refresh way should take effect, but it seems not.
yahman72 commentedon Oct 9, 2015
Some thoughts about this (triggered by #2165):
ResourceKW in*** Settings ***?BuiltIn.Import ResourceKW (e.g. withforce_reimport=Falsearg?3.a) if a variable is already imported from the same resource file e.g.
var_a = fooinmy_resource_a.robota KW updates to
var_a = barmy_resource_a.robotis imported again withvar_a = foo--> what should be the value of
var_afooorbar?3.b) if a variable is already imported from another resource file e.g.
my_resource_B.robotis imported withvar_a = barmy_resource_a.robotis imported withvar_a = foo--> what should be the value of
var_afooorbar?I use resource files quite often for "overriding default values" i.e.
my_test_suite.robotimportstest_vars_resource.robot(e.g.var_a = bar) andsome_KWs_resource.robotsome_KWs_resource.robotimportsdefault_vars.robot(e.g.var_a = foo)--> in these cases overriding
var_avalue would be highly undesiredpahalampi commentedon May 5, 2021
I recently faced this same issue with RF 3.2.2, while trying to reload my
variables.py-file for each test case.The reload functionality would be really handy in the
Import Variables-keyword, but as it does not support it currently, I came up with a workaround which I run in each test cases setup: