From 07d9d13240c8ca0320432c249ddc2904b35e0976 Mon Sep 17 00:00:00 2001 From: Dries Peeters Date: Fri, 14 Nov 2025 21:34:33 +0100 Subject: [PATCH] Update conftest.py --- tests/conftest.py | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b87cf9e..f67e65b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -360,26 +360,25 @@ def multiple_users(app): @pytest.fixture def test_client(app, user): """Create a test client (business client, not test client).""" - with app.app_context(): - client_model = Client( - name='Test Client Corp', - description='Test client for integration tests', - contact_person='John Doe', - email='john@testclient.com', - phone='+1 (555) 123-4567', - address='123 Test Street, Test City, TC 12345', - default_hourly_rate=Decimal('85.00') - ) - client_model.status = 'active' # Set after creation - db.session.add(client_model) - # Flush to assign primary key before commit to avoid expired attribute reloads - db.session.flush() - client_id = client_model.id - db.session.commit() - # Re-query to ensure we return a persistent instance without relying on refresh - persisted_client = Client.query.get(client_id) or Client.query.filter_by(id=client_id).first() - # Fallback to the original instance if re-query unexpectedly returns None - return persisted_client or client_model + client_model = Client( + name='Test Client Corp', + description='Test client for integration tests', + contact_person='John Doe', + email='john@testclient.com', + phone='+1 (555) 123-4567', + address='123 Test Street, Test City, TC 12345', + default_hourly_rate=Decimal('85.00') + ) + client_model.status = 'active' # Set after creation + db.session.add(client_model) + # Flush to assign primary key before commit to avoid expired attribute reloads + db.session.flush() + client_id = client_model.id + db.session.commit() + # Re-query to ensure we return a persistent instance without relying on refresh + persisted_client = Client.query.get(client_id) or Client.query.filter_by(id=client_id).first() + # Fallback to the original instance if re-query unexpectedly returns None + return persisted_client or client_model @pytest.fixture