Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strange behaviour when unittesting with singleton lambda handler #16

Closed
sloev opened this issue Mar 13, 2017 · 1 comment
Closed

strange behaviour when unittesting with singleton lambda handler #16

sloev opened this issue Mar 13, 2017 · 1 comment
Labels

Comments

@sloev
Copy link
Owner

sloev commented Mar 13, 2017

when unittesting code like the following

from lambdarest import lambda_handler

@lambda_handler.handle("get")
def my_own_get(event):
    return {"this": "will be json dumped"}

The lambda_handler singleton will stay instantiated between testcases since the module is not torn down completely (unittest does this to be able to later on gather the test results see https://chrisbailey.blogs.ilrt.org/2013/05/19/pythons-leaky-testcase-aka-hidden-gotchas-using-self/)

This means that the same lambda_handler instance will be used for all testcases, them being in different files or not. Which again means that the internal lookup http_methods will be scrampled.

A fix for this is to either put your import statements locally in your test functions like:

class test(unittest.TestCase):
    def test_this(self):
        from my_module import lambda_handler
        lambda_handler.handle("get")

or stop using the singleton and instantiate your own like:

from lambdarest import create_lambda_handler
lambda_handler = create_lambda_handler()
@sloev sloev added the wontfix label Mar 13, 2017
@sloev
Copy link
Owner Author

sloev commented Mar 13, 2017

issue has been mentioned in README

@sloev sloev closed this as completed Mar 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant