benc-uk/python-demoapp

make test error : TypeError: '>' not supported between instances of 'NoneType' and 'int'

Opened this issue · 1 comments

================================================================================= FAILURES =================================================================================
_____________________________________________________________________________ test_api_process _____________________________________________________________________________

client = <FlaskClient <Flask 'app'>>

def test_api_process(client):
    resp = client.get("/api/process")

    assert resp.status_code == 200
    assert resp.headers["Content-Type"] == "application/json"
    resp_payload = json.loads(resp.data)
    assert len(resp_payload["processes"]) > 0
  assert resp_payload["processes"][0]["memory_percent"] > 0

E TypeError: '>' not supported between instances of 'NoneType' and 'int'

src/app/tests/test_api.py:12: TypeError
========================================================================= short test summary info ==========================================================================
FAILED src/app/tests/test_api.py::test_api_process - TypeError: '>' not supported between instances of 'NoneType' and 'int'
======================================================================= 1 failed, 4 passed in 3.21s ========================================================================
make: *** [test] Error 1

My answer is not a proper solution but you can try it anyway.

# Test the process API returns JSON results we expect
def test_api_process(client):
    resp = client.get("/api/process")

    assert resp.status_code == 200
    assert resp.headers["Content-Type"] == "application/json"
    resp_payload = json.loads(resp.data)
    processes = resp_payload["processes"]
    assert len(processes) > 0
    assert processes[0]["memory_percent"] == None or processes[0]["memory_percent"] > 0
    assert len(processes[0]["name"]) == None or len(processes[0]["name"]) > 0

I think this error happened because I'm running this code on Mac M1