Purpose:
Access / write to the same temporary files when using the general utility function called from various python modules.
Background:
I am using the Uittest python module to run custom test suites that interact with tools through pySerial. Since I use the unittest module, I cannot pass the required variables, for example, which serial port to use, to the unittest test case. To get around this, I want to create a module that stores and returns pickled data. I ran into a problem that when I call the get_foo () function from test_case_1 (), it tries to load the pickled data from a relative path based on test_case_1 (), and not the actual module that contains get_foo ().
It is worth noting that I have considered using global variables, but there is some data that I want to save from run to run. This means that all python modules will be closed, and I want to reload the data that was saved in the previous execution.
I am in SO question: Python - how to relate to relative resource paths when working with a code repository , I thought I found a solution in the first answer. To my horror, this does not work for me in Python 2.7 (Debian)
Is there a reliable way to return the path to a specific file when called from different modules?
source
share