diff --git a/0001-Fix-rmtree-failure-in-tearDown.patch b/0001-Fix-rmtree-failure-in-tearDown.patch
new file mode 100644
index 0000000..462182d
--- /dev/null
+++ b/0001-Fix-rmtree-failure-in-tearDown.patch
@@ -0,0 +1,85 @@
+From 7ee6f0be21c9c841e14e1c1008cf7c3634da0831 Mon Sep 17 00:00:00 2001
+From: Tomas Orsava <torsava@redhat.com>
+Date: Fri, 18 Aug 2017 14:37:16 +0200
+Subject: [PATCH] Fix rmtree failure in tearDown
+
+We need to remove the S.gpg-agent sockets, because when one of the
+sockets gets closed by shutil.rmtree, gpg will try to close the 3
+remaining sockets and may do it before shutil.rmtree deletes them.
+This results in rmtree trying to delete a non existing file and can
+exiting with an error `No such file or directory`.
+---
+ tests/python/tests/test_yum_repo_downloading.py | 17 ++++++++++++++++-
+ tests/python/tests/test_yum_repo_locating.py    | 17 ++++++++++++++++-
+ 2 files changed, 32 insertions(+), 2 deletions(-)
+
+diff --git a/tests/python/tests/test_yum_repo_downloading.py b/tests/python/tests/test_yum_repo_downloading.py
+index ad597dc..0049946 100644
+--- a/tests/python/tests/test_yum_repo_downloading.py
++++ b/tests/python/tests/test_yum_repo_downloading.py
+@@ -2,7 +2,7 @@ import sys
+ import time
+ import gpgme
+ import shutil
+-import os.path
++import os
+ import tempfile
+ import unittest
+ 
+@@ -32,6 +32,21 @@ class TestCaseYumRepoDownloading(TestCaseWithFlask):
+             os.environ.pop('GNUPGHOME')
+         else:
+             os.environ['GNUPGHOME'] = self._gnupghome
++
++        # We need to remove the S.gpg-agent sockets, because when one of the
++        # sockets gets closed by shutil.rmtree, gpg will try to close the 3
++        # remaining sockets and may do it before shutil.rmtree deletes them.
++        # This results in rmtree trying to delete a non existing file and can
++        # exiting with an error `No such file or directory`.
++        try:
++            gpg_agent_files = ["S.gpg-agent", "S.gpg-agent.browser",
++                               "S.gpg-agent.extra", "S.gpg-agent.ssh"]
++            for file in gpg_agent_files:
++                os.remove(os.path.join(self.tmpdir, "keyring", file))
++        except OSError:
++            # GPG deleted the remaining file(s) faster then we did
++            pass
++
+         shutil.rmtree(self.tmpdir)
+ 
+     def test_download_repo_01(self):
+diff --git a/tests/python/tests/test_yum_repo_locating.py b/tests/python/tests/test_yum_repo_locating.py
+index 8f4bea5..02d6aea 100644
+--- a/tests/python/tests/test_yum_repo_locating.py
++++ b/tests/python/tests/test_yum_repo_locating.py
+@@ -1,4 +1,4 @@
+-import os.path
++import os
+ import tempfile
+ import shutil
+ import unittest
+@@ -34,6 +34,21 @@ class TestCaseYumRepoLocating(TestCase):
+             os.environ.pop('GNUPGHOME')
+         else:
+             os.environ['GNUPGHOME'] = self._gnupghome
++
++        # We need to remove the S.gpg-agent sockets, because when one of the
++        # sockets gets closed by shutil.rmtree, gpg will try to close the 3
++        # remaining sockets and may do it before shutil.rmtree deletes them.
++        # This results in rmtree trying to delete a non existing file and can
++        # exiting with an error `No such file or directory`.
++        try:
++            gpg_agent_files = ["S.gpg-agent", "S.gpg-agent.browser",
++                               "S.gpg-agent.extra", "S.gpg-agent.ssh"]
++            for file in gpg_agent_files:
++                os.remove(os.path.join(self.tmpdir, "keyring", file))
++        except OSError:
++            # GPG deleted the remaining file(s) faster then we did
++            pass
++
+         shutil.rmtree(self.tmpdir)
+ 
+     def test_read_mirrorlist(self):
+-- 
+2.13.5
+
diff --git a/librepo.spec b/librepo.spec
index e08c052..916a8cf 100644
--- a/librepo.spec
+++ b/librepo.spec
@@ -14,13 +14,15 @@
 
 Name:           librepo
 Version:        1.7.20
-Release:        8%{?dist}
+Release:        9%{?dist}
 Summary:        Repodata downloading library
 
 License:        LGPLv2+
 URL:            https://github.com/rpm-software-management/librepo
 Source0:        %{url}/archive/%{name}-%{version}/%{name}-%{version}.tar.gz
 
+Patch0:         0001-Fix-rmtree-failure-in-tearDown.patch
+
 BuildRequires:  cmake
 BuildRequires:  gcc
 BuildRequires:  check-devel
@@ -90,7 +92,7 @@ Python 3 bindings for the librepo library.
 %endif # with platform_python
 
 %prep
-%autosetup -n %{name}-%{name}-%{version}
+%autosetup -n %{name}-%{name}-%{version} -p1
 
 mkdir build build-py3 build-platpy
 
@@ -206,6 +208,9 @@ popd
 %endif # with platform_python
 
 %changelog
+* Fri Aug 18 2017 Tomas Orsava <torsava@redhat.com> - 1.7.20-9
+- Added Patch 0 to fix a tearDown failure in the test suite
+
 * Thu Aug 10 2017 Petr Viktorin <pviktori@redhat.com> - 1.7.20-8
 - Add subpackage for platform-python (https://fedoraproject.org/wiki/Changes/Platform_Python_Stack)