Revision: f6925e5f6a52
Branch:   default
Author:   Pekka Klärck
Date:     Thu Apr 17 07:55:07 2014 UTC
Log: Initial implementation for better reporting if using execution context via BuiltIn when RF not running.

Update issue 1667
Status: Started
Owner: pekka.klarck
Here's initial implementation. It still uses AttributeError because I thought it would be more backwards-compatible. After thinking this a little more, and re-reading the issue description, I'm convinced we need to use something else.

Any comments which exception should we use? Best existing Robot exceptions is DataError but it isn't exactly correct in this case. Best standard Python exception is probably RuntimeError, but that's probably bit too generic.

Should we just add a new exception? What name? Where? Other exceptions are in robot.errors module, but having this in BuiltIn would work too:

    from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
http://code.google.com/p/robotframework/source/detail?r=f6925e5f6a52

Added:
 /utest/api/test_using_libraries.py
Modified:
 /src/robot/libraries/BuiltIn.py

=======================================
--- /dev/null
+++ /utest/api/test_using_libraries.py  Thu Apr 17 07:55:07 2014 UTC
@@ -0,0 +1,17 @@
+import unittest
+
+from robot.utils.asserts import assert_raises_with_msg
+from robot.libraries.BuiltIn import BuiltIn
+
+
+class TestBuiltIn(unittest.TestCase):
+
+    def test_error_when_using_namespace_and_robot_not_running(self):
+        assert_raises_with_msg(AttributeError,
+                               'Cannot access execution context when '
+                               'Robot Framework is not running.',
+                               BuiltIn().get_variables)
+
+
+if __name__ == '__main__':
+    unittest.main()
=======================================
--- /src/robot/libraries/BuiltIn.py     Thu Jan 23 14:00:53 2014 UTC
+++ /src/robot/libraries/BuiltIn.py     Thu Apr 17 07:55:07 2014 UTC
@@ -2649,6 +2649,9 @@

     @property
     def _context(self):
+        if EXECUTION_CONTEXTS.current is None:
+            raise AttributeError('Cannot access execution context when '
+                                 'Robot Framework is not running.')
         return EXECUTION_CONTEXTS.current

     @property

--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to