cnaas-nms icon indicating copy to clipboard operation
cnaas-nms copied to clipboard

session.py side effects

Open stveit opened this issue 4 years ago • 0 comments

Is your feature request related to a problem? Please describe. We have had issues regarding the session.py module. The module automatically runs code for connecting to the database. So when we want to test just a function (a unit test if you will), and this module imports from session.py then the program will crash if there is no db to connect to. This also of course happens if the module you test imports another module which imports session.py, so this can be quite frustrating.

Describe the solution you'd like We want the session.py to not automatically attempt to connect to the database when imported. The simplest solution would be to just put the code in a function, and call the function when its needed. As far as i can see, the only code that references any of the varibles created is the sqla_session function. So creating a function, and calling the function from sqla_session.py is a solution.

stveit avatar Nov 18 '21 12:11 stveit