whatever tool you are using is telling you there is a ResourceClosedError. That 
error message should be accompanied by a stack trace. if you're running unit 
tests in Python, as opposed to you're on some remote system and looking in log 
files, these should be very obvious as every unit test runner is going to be 
dumping out stack traces.


On Thu, Jan 16, 2020, at 9:42 AM, Mirek Morek wrote:
> Ok, I see that. Could you give me some hint how could I provide the useful 
> stack trace? What tool should I use?
> 
> W dniu czwartek, 16 stycznia 2020 01:24:52 UTC+1 użytkownik Mike Bayer 
> napisał:
>> there's no way to tell from here, information like the stack trace, and how 
>> the tests are being run (like what test runner, any multiprocessing in use, 
>> etc.) would be places to start.
>> 
>> 
>> 
>> On Mon, Jan 13, 2020, at 9:35 AM, Mirek Morek wrote:
>>> Hello,
>>> I use sqlalchemy to execute my tests on Postgres Database. I run like ~200 
>>> tests, every test uses its own setup and teardown. creates a connection and 
>>> closes it after all.
>>> 
>>> I sometimes get *ResourceClosedError *(*"StatementError: 
>>> (sqlalchemy.exc.ResourceClosedError) This Connection is closed"** *in 
>>> random places when tests are running one after another. It was not present 
>>> on Sybase database. It seems like it wants to work on a closed 
>>> connection...?
>>> For a single test run I never got that. 
>>> 
>>> Do you have any idea, what I could improve? This is a part of my code:
>>> 
>>> 
>>> from sqlalchemy import create_engine
>>> from sqlalchemy.orm import create_session
>>> from configuration import PostgresConfiguration as PGS
>>> 
>>> class PostgresDatabase:
>>>     def __init__(self):
>>>         self.connection_string = r'postgresql://{}:{}@{}:{}/{}'.format(
>>>             PGS.DB_USER,
>>>             PGS.DB_PASSWORD,
>>>             PGS.DB_HOST.split(":")[0],
>>>             PGS.DB_HOST.split(":")[1],
>>>             PGS.DB_NAME)
>>>         self.engine = create_engine(self.connection_string, echo=True, 
>>> label_length=30)
>>>         self.session = create_session(self.engine)
>>>         self.database_name = PGS.DB_NAME
>>> 
>>>     def get_session(self):
>>>         *"""
**        Retrieves current session.
**        ***:return***: current session.
**        """
**        *return self.session
>>> 
>>>     def close_session(self):
>>>         *"""
**        Closes all open sessions.
**        """
**        *self.session.close_all()
>>> 
>>>     def execute_query(self, query, commit=True):
>>>         *"""
**        Executes query passes as a parameter.
**        ***:param*** query: passed query to be executed.
**        ***:param*** commit: if True session will be committed
**        ***:return*** query execution results
**        """
**        *if commit:
>>>             self.session.begin()
>>>             results = self.session.execute(query)
>>>             self.session.commit()
>>>         else:
>>>             results = self.session.execute(query)
>>>         return results
>>> 

>>> --
>>> SQLAlchemy - 
>>> The Python SQL Toolkit and Object Relational Mapper
>>> 
>>> http://www.sqlalchemy.org/
>>> 
>>> To post example code, please provide an MCVE: Minimal, Complete, and 
>>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
>>> description.
>>> --- 
>>> You received this message because you are subscribed to the Google Groups 
>>> "sqlalchemy" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to [email protected].
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/sqlalchemy/95b083fa-6fb7-4000-b0f9-6e9787f5f540%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/sqlalchemy/95b083fa-6fb7-4000-b0f9-6e9787f5f540%40googlegroups.com?utm_medium=email&utm_source=footer>.
>> 
> 

> --
>  SQLAlchemy - 
>  The Python SQL Toolkit and Object Relational Mapper
> 
> http://www.sqlalchemy.org/
> 
>  To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
>  --- 
>  You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
>  To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
>  To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/7004867d-f728-4133-8099-6509d010ae4d%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/7004867d-f728-4133-8099-6509d010ae4d%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/da656e4f-6d48-4167-9b74-ca90f7bbf37b%40www.fastmail.com.

Reply via email to