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',