简体   繁体   中英

python bottle boddle - patch(… side-effect="Exception) not working. What am I doing wrong

With: Python 3.7, Bottle, Boddle, Requests

I have one module to be tested (server), and a second module with the test code (test).

The tested code (server.py):

 @bt_app.post("/") def server_post(): try: bt.request.forms.get("msg", None) except bt.BottleException: print("BottleException")

Testing code (test.py):

 def test_test(): with boddle(), \ patch( "server.bt.request.forms.get", side_effect=server.bt.BottleException, ), \ pytest.raises(server.bt.BottleException): server.server_post()

I first run 'server', which successfully sets up a server.

I then run 'test', which successfully accesses and tests the server.

I expect the test to raise "BottleException" and PASS, but it does not. It DOES properly fail stating: "Failed: DID NOT RAISE <class 'bottle.BottleException'>"

Can anyone give me a pointer of what I'm doing wrong?

Thanks

Try it without the alias.

...
with pytest.raises(bottle.BottleException):
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM