[qmtest] Questions [context scope, prerequisites enforcement]

Mohamed Barwani mohamedb at sgi.com
Fri Apr 11 00:14:52 UTC 2008


Thanks Stefan!

Question 2 solved..

Stefan Seefeld wrote:
> Hi Mohamed,
> 
> Mohamed Barwani wrote:
>> Hello there..
>> 
>> _1_ Am trying to get my head around python.. Looking at the context
>>  variable I can easily create new items it in a 'resource' object,
>> but not in a 'test' object.
> 
> All context variables live in the Context object, which is passed to
>  Resource.SetUp() as well as Test.Run(), where you can access as well
> as modify them.

An example would illustrate what I mean. test_a sets a context variable, 
where test_b tries to use it.

?<[shark:~/workarea/qmtest_bed]
?<> cat test_*
<?xml version="1.0" ?>
<!DOCTYPE extension
   PUBLIC '-//QM/2.4/Extension//EN'
   'http://www.codesourcery.com/qm/dtds/2.4/-//qm/2.4/extension//en.dtd'>
<extension class="python.ExecTest" kind="test">
    <argument name="prerequisites"><set/></argument>
    <argument name="source">
      <text>context['test_a.var'] = "some_val"</text>
    </argument>
    <argument name="target_group"><text>.*</text></argument>
    <argument name="expression"><text>1</text></argument>
    <argument name="resources"><set/></argument>
</extension>
<?xml version="1.0" ?>
<!DOCTYPE extension
   PUBLIC '-//QM/2.4/Extension//EN'
   'http://www.codesourcery.com/qm/dtds/2.4/-//qm/2.4/extension//en.dtd'>
<extension class="python.ExecTest" kind="test">
   <argument name="prerequisites"><set/></argument>
   <argument name="source">
     <text>print context
print context['test_a.var']
     </text>
   </argument>
   <argument name="target_group"><text>.*</text></argument>
   <argument name="expression"><text>1</text></argument>
   <argument name="resources"><set/></argument>
</extension>
?<[shark:~/workarea/qmtest_bed]
?<> qmtest run test_a test_b
--- TEST RESULTS 
-------------------------------------------------------------

   test_a                                        : PASS

{'qmtest.tmpdir': '/tmp/tmpRA4MY8', 'qmtest.target': 'local', 
'qmtest.dbpath': '/home/mohamedb/workarea/qmtest_bed', 'qmtest.id': 
'test_b'}
   test_b                                        : ERROR
     Exception executing source.

     qmtest.context_variable:
       test_a.var

     qmtest.end_time:
       2008-04-11T00:08:16Z

     qmtest.exception:

       qm.test.context.ContextException: The context variable 
"test_a.var" was not defined.


     qmtest.start_time:
       2008-04-11T00:08:16Z

     qmtest.target:
       local

     qmtest.traceback:

         File 
"/usr/lib/python2.4/site-packages/qm/test/classes/python.py", line 87, 
in Run
           exec self.source in global_namespace, local_namespace

         File "<string>", line 2, in ?

         File 
"/home/mohamedb/Desktop/qmtest-2.4/build/lib.linux-x86_64-2.4/qm/test/context.py", 
line 298, in __getitem__
           return self.__context[key]

         File 
"/home/mohamedb/Desktop/qmtest-2.4/build/lib.linux-x86_64-2.4/qm/test/context.py", 
line 296, in __getitem__
           raise ContextException(key)


--- TESTS THAT DID NOT PASS 
--------------------------------------------------

   test_b                                        : ERROR
     Exception executing source.


--- STATISTICS 
---------------------------------------------------------------

        2        tests total
        1 ( 50%) tests ERROR
        1 ( 50%) tests PASS


Thanks for your help again..
-- 
Mohamed Barwani
ASGQA
"The greatest challenge to any thinker is stating the problem in a way
that will allow a solution."
     - Bertrand Russell



More information about the qmtest mailing list