In unit tests, Application comparisons can report false positive #1866
Closed
Description
Comparison between Application is performed at the MutableMapping level. MutableMapping says that, like dict objects, if all keys and matching values are the same 2 instances, then they are equals. This means that web.Application() == web.Application() will return True.
See:
>>> a = aiohttp.web.Application()
>>> b = aiohttp.web.Application()
>>> a == b
True
>>> a["foo"] = "bar"
>>> a == b
False
>>> b["foo"] = "bar"
>>> a == b
TrueI think those few unit tests are assuming a different behaviour:
- test_subapp_middlewares
- test_subapp_on_response_prepare
- test_subapp_on_startup
- test_subapp_on_shutdown
- test_subapp_on_cleanup
A change has been submitted for test_subapp_middlewares in #1854 to fix that. While the solution may or may not be accepted as is, all tests should be fixed.
Also, maybe an additional test_application_equal should be implemented, to be ensure expected behavior. Unless web.Application.__eq__ special method gets implemented to change current behaviour, it should look like something like that:
def test_application_equal():
app1 = web.Application()
app2 = web.Application()
assert app1 == app2
app1["foo"] = "bar"
assert app1 != app2