# Importing variables not working?

**URL:** <https://forum.robotframework.org/t/importing-variables-not-working/2892>\
**Category:** Robot Framework\
**Created:** [1 December 2021 23:56 UTC](https://forum.robotframework.org/t/importing-variables-not-working/2892 "2021-12-01T23:56:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [1 December 2021 23:56 UTC](https://forum.robotframework.org/t/importing-variables-not-working/2892/1 "2021-12-01T23:56:49Z")

</div>

Hello all,

I was just testing an old file from 2016 and tests failed with unexpected variable not defined. Can you please confirm this? Thanks.

Execution on Fedora Linux 34 with Robot 4.1.2:

```python
robot external_vars_test.robot 
==============================================================================
External Vars Test :: A test file using external variables. Created on 3/14...
==============================================================================
Today is 3.14 2016 Pi day :: Testing external variables | FAIL |
Variable '${name}' not found. Did you mean:
    ${TEST_NAME}
------------------------------------------------------------------------------

```

This is output from Python 3.9.7:

```python
>>> from external_vars import *
>>> print(name)
Archimedes

```

This is the variable file:

```python
from math import pi

name = "Archimedes"
city = "Syracuse"
radius = 6.5
better_Pi = pi
# DATA = "this is argument: %s" % args[0]

def get_variables(args=None):
        DATA = {"data" : "this is argument: %s" % args}
        return DATA

```

And this is the test case:

```python
***Settings***
Documentation A test file using external variables.
... Created on 3/14/2016.
... Another line added on 8/9/2017 (to see ...)
Variables ${CURDIR}/external_vars.py
Library OperatingSystem WITH NAME OS

***Variables***
${PI_DAY} 3.1416

***Test Cases***
Today is 3.14 2016 Pi day
    [Documentation] Testing external variables
    Log Today is Pi day celebration\nThis is the basic value of Pi: ${PI_DAY}
    Log Pi was calculated by ${name} from ${city}
    Log The Python's value of Pi is: ${better Pi}
    ${my area}= Evaluate 2*${PI_DAY}*${radius}**2
    ${better_area} Evaluate 2*${better Pi}*${radius}**2
    ${error}= Evaluate ${better area}-${my area}
    Log An example of the use of Pi is to calculate the area of a circle.\n We have a circle with radius = ${radius} units. We get ${my area} and ${better area} depending of the accuracy of the value of Pi.\n As we can see, the error is ${error}.\n One more line.\n WARN
    Log Variables
    Log Second editing example of the use of Pi is to calculate the area of a circle.\n We have a circle with radius = ${radius} units. We get ${my area} and ${better area} depending of the accuracy of the value of Pi.\n As we can see, the error is ${error}.\n One more line.\n
    Log To Console This message goes only to Console.
    No Operation
    Log Many
    Comment No Operation \ The Python's value of Pi is: ${better Pi}
    Log This message goes only to Console.
    Log To Console ${PREV_TEST_STATUS}
    Comment
    Set Environment Variable HTTP_TEST abcde

Set env var
    ${HTTP_TEST}= Get Environment Variable HTTP_TEST This is the default
    Set Environment Variable HTTP_TEST ${HTTP_TEST}
    Log %{HTTP_TEST}
    Log ${PI_DAY}

Show env var
    Log %{HTTP_TEST}
    Log ${PI_DAY}

```

---

<div class="post-metadata">

**Author:** ![pekkaklarck](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/pekkaklarck/32/1019_2.png) [@pekkaklarck](https://forum.robotframework.org/u/pekkaklarck)\
**Post date:** [2 December 2021 00:03 UTC](https://forum.robotframework.org/t/importing-variables-not-working/2892/2 "2021-12-02T00:03:52Z")

</div>

That variable file has `get_variables` so variables are got by calling it, not from the file directly. This behavior hasn’t changed.

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [2 December 2021 00:14 UTC](https://forum.robotframework.org/t/importing-variables-not-working/2892/3 "2021-12-02T00:14:18Z")

</div>

I was not aware of that special function.  
But is was working without calling it (or am I wrong?).

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [2 December 2021 00:18 UTC](https://forum.robotframework.org/t/importing-variables-not-working/2892/4 "2021-12-02T00:18:06Z")

</div>

Indeed, commenting that definition of `get_variables`, makes the test pass.

This is a strange effect. I created a function with special meaning.

---

<div class="post-metadata">

**Author:** ![pekkaklarck](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/pekkaklarck/32/1019_2.png) [@pekkaklarck](https://forum.robotframework.org/u/pekkaklarck)\
**Post date:** [2 December 2021 09:13 UTC](https://forum.robotframework.org/t/importing-variables-not-working/2892/5 "2021-12-02T09:13:21Z")

</div>

The User Guide explains how that function works in detail. It has been supported for ages.

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [2 December 2021 10:44 UTC](https://forum.robotframework.org/t/importing-variables-not-working/2892/6 "2021-12-02T10:44:41Z")

</div>

Well, I started by saying that is a test from 2016. I just got surprised by the normal variables definitions stopped working when that function exists. In my view they could co-exist.

---

<div class="post-metadata">

**Author:** ![pekkaklarck](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/pekkaklarck/32/1019_2.png) [@pekkaklarck](https://forum.robotframework.org/u/pekkaklarck)\
**Post date:** [2 December 2021 14:07 UTC](https://forum.robotframework.org/t/importing-variables-not-working/2892/7 "2021-12-02T14:07:04Z")

</div>

I think `get_variables` has been supported already before RF was open sourced. Couldn’t easily find references when it was added, but it certainly existed in 2009 because it was enhanced in RF 2.5:

> <https://github.com/robotframework/robotframework/issues/427>
>
> \> \_Originally submitted to \[Google Code\](http://code.google.com/p/robotframework…/issues/detail?id=427) by bryan.oakley on 2 Nov 2009\_
> 
> I have a variable file that creates a subclass of dict to implement some
> custom behavior. When I try to load that with robot it complains
> "get\_variables returned '&lt;class 'locator.LocatorDict'&gt;', expected a
> dictionary". 
> 
> It would be useful to allow get\_variables to return anything that has the
> same interface as a dict rather than only allowing dicts.

I don’t think it could really co-exist with normal variables. A major problem normal variables, i.e. reading them directly from the variable file module, is that nearly everything becomes a variable. `get_variables` is one way to avoid that. In addition to losing that functionality, changing this would be very badly backwards incompatible.

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [2 December 2021 14:10 UTC](https://forum.robotframework.org/t/importing-variables-not-working/2892/8 "2021-12-02T14:10:56Z")

</div>

Thanks. I probably added the function later to my initial test. Will see if my keyword work or if it is ignored and superseded by the builtin.
