From 86c79072426fc46711d9b19888c49fcc467de6da Mon Sep 17 00:00:00 2001 From: Felix Kotschenreuther Date: Sat, 1 Jul 2023 12:52:16 +1200 Subject: [PATCH] fix: fixed bug where teardown of PCO class without parameters tries to close self.session, wich does not exit at that time --- pypco/pco.py | 4 ++-- tests/test_pco.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pypco/pco.py b/pypco/pco.py index c94c2a0..8a59b9a 100644 --- a/pypco/pco.py +++ b/pypco/pco.py @@ -536,8 +536,8 @@ def upload(self, file_path: str, **params) -> Optional[dict]: # pylint: disable def __del__(self): """Close the requests session when the PCO object goes out of scope.""" - - self.session.close() + if self.session is not None: + self.session.close() @staticmethod def template( diff --git a/tests/test_pco.py b/tests/test_pco.py index e524868..338cb21 100644 --- a/tests/test_pco.py +++ b/tests/test_pco.py @@ -11,7 +11,7 @@ import pypco from pypco.exceptions import PCORequestTimeoutException, \ - PCORequestException, PCOUnexpectedRequestException + PCORequestException, PCOUnexpectedRequestException, PCOCredentialsException from pypco.auth_config import PCOAuthConfig from tests import BasePCOTestCase, BasePCOVCRTestCase @@ -775,6 +775,10 @@ class TestPCOInitialization(BasePCOTestCase): def test_pco_initialization(self): """Test initializing the PCO object with various combinations of arguments.""" + # region no Args: + with self.assertRaises(PCOCredentialsException): + pypco.PCO() + # region Minimal Args: PAT Auth pco = pypco.PCO( 'app_id',