From ab919c00db1f67f4c3f60e4210ed24d5b8ef8d70 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 24 Feb 2021 09:32:58 +0100 Subject: [PATCH] [FIX] conftest: ensure we always have a reason in get_ref Apparently the "reason phrase" has been removed from HTTP/2 and github has enabled HTTP/2, meaning responses may or may not contain a reason phrase depending whether they're HTTP/1.1 or HTTP/2. Now I don't understand how this triggers because requests isn't supposed to support HTTP/2, and in a shell I do get a reason, but w/e. Anyway the reason is used by a few tests to check more specifically for the response they're getting, as that's used as the assertion message by `get_ref`. I guess I could replace the AssertionError by an HTTPError but... w/e. Seems simpler to just fallback to the generic reason based on the status code. It fixes both failing tests (test_straightforward_flow and test_delete_normal) with very little change. --- conftest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/conftest.py b/conftest.py index 0c7e5568..017c0f6b 100644 --- a/conftest.py +++ b/conftest.py @@ -43,6 +43,7 @@ import base64 import collections import configparser import copy +import http.client import itertools import logging import os @@ -493,7 +494,7 @@ class Repo: if re.match(r'[0-9a-f]{40}', ref): # just check that the commit exists r = self._session.get('https://api.github.com/repos/{}/git/commits/{}'.format(self.name, ref)) - assert 200 <= r.status_code < 300, r.reason + assert 200 <= r.status_code < 300, r.reason or http.client.responses[r.status_code] return r.json()['sha'] if ref.startswith('refs/'): @@ -502,7 +503,7 @@ class Repo: ref = 'heads/' + ref r = self._session.get('https://api.github.com/repos/{}/git/ref/{}'.format(self.name, ref)) - assert 200 <= r.status_code < 300, r.reason + assert 200 <= r.status_code < 300, r.reason or http.client.responses[r.status_code] res = r.json() assert res['object']['type'] == 'commit' return res['object']['sha']