From e542dfc8520166ff0a4e33e6d108cbd73b7efc59 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 6 Apr 2021 10:52:51 +0200 Subject: [PATCH] [IMP] repo creation error handling + warnings * The repo would only be registered at the very end of the creation, meaning an error *during* the repo creation (e.g. while uploading the first blob or setting up webhooks) would leave the repository undeleted. Register the repository as soon as we know it was created, in order to correctly dispose of it afterwards. * Migrate logging.warning call to warnings.warn on repository deletion failure: pytest will print warnings during its reporting, not so for log warnings (?) --- conftest.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/conftest.py b/conftest.py index 959cee42..83d88889 100644 --- a/conftest.py +++ b/conftest.py @@ -54,6 +54,7 @@ import subprocess import sys import time import uuid +import warnings import xmlrpc.client from contextlib import closing @@ -383,6 +384,7 @@ def make_repo(capsys, request, config, tunnel, users): 'allow_rebase_merge': False, }) r.raise_for_status() + repo = Repo(github, fullname, repos) # create webhook github.post('{}/hooks'.format(repo_url), json={ @@ -401,8 +403,9 @@ def make_repo(capsys, request, config, tunnel, users): 'content': base64.b64encode(b'whee').decode('ascii'), 'branch': 'garbage_%s' % uuid.uuid4() }).raise_for_status() - - return Repo(github, fullname, repos) + # try to unwatch repo, doesn't actually work + repo.unsubscribe() + return repo yield repomaker @@ -433,9 +436,6 @@ class Repo: self.hook = False repos.append(self) - # unwatch repo - self.unsubscribe() - @property def owner(self): return self.name.split('/')[0] @@ -470,7 +470,7 @@ class Repo: def delete(self): r = self._session.delete('https://api.github.com/repos/{}'.format(self.name)) if r.status_code != 204: - logging.getLogger(__name__).warning("Unable to delete repository %s", self.name) + warnings.warn("Unable to delete repository %s (HTTP %s)" % (self.name, r.status_code)) def set_secret(self, secret): assert self.hook