Skip to content

test: Standardize service mocking with shared pytest fixtures for reliable test isolation#11350

Merged
Cristhianzl merged 1 commit into
mainfrom
cz/fix-services-lfx-test
Jan 19, 2026
Merged

test: Standardize service mocking with shared pytest fixtures for reliable test isolation#11350
Cristhianzl merged 1 commit into
mainfrom
cz/fix-services-lfx-test

Conversation

@Cristhianzl
Copy link
Copy Markdown
Member

@Cristhianzl Cristhianzl commented Jan 19, 2026

This pull request improves the reliability and isolation of unit tests for service registration and management by introducing shared fixtures for mocking service dependencies, especially for the session_service. The changes ensure that all tests involving services with dependencies (like LocalStorageService) use consistent, controlled mock objects, leading to more robust and predictable test outcomes.

Test Infrastructure Improvements:

  • Added a new conftest.py with shared pytest fixtures for mock_session_service, mock_settings_service, and a service_manager_with_session that registers a mock session service for dependency injection in tests.
  • Updated all test modules to import and use MockSessionService and the new fixtures for dependency injection, ensuring that services like LocalStorageService are always provided with required mock dependencies. [1] [2] [3]

Test Logic and Assertion Updates:

  • Modified test setup in multiple test classes and fixtures to register the mock session service (SESSION_SERVICE) with the ServiceManager, ensuring correct dependency resolution in all scenarios. [1] [2] [3] [4] [5] [6] [7] [8] [9]
  • Adjusted assertions in tests to account for the presence of the mock SESSION_SERVICE in the registered service classes, updating expected service counts and checks accordingly. [1] [2] [3] [4] [5] [6]

Test Refactoring for Consistency:

  • Refactored LocalStorageService instantiations in tests to use the new mock fixtures instead of passing file paths directly, and updated path assertions to use the mock settings service's config directory. [1] [2] [3] [4] [5]

These changes collectively ensure that all unit tests for services are isolated from the real environment and dependencies, making them more reliable and maintainable.

Summary by CodeRabbit

  • Tests
    • Enhanced test infrastructure with improved mock service fixtures and streamlined test setup for service manager validation.

✏️ Tip: You can customize this high-level summary in your review settings.

@Cristhianzl Cristhianzl self-assigned this Jan 19, 2026
@Cristhianzl Cristhianzl merged commit d62a9a6 into main Jan 19, 2026
11 of 15 checks passed
@Cristhianzl Cristhianzl deleted the cz/fix-services-lfx-test branch January 19, 2026 11:08
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 19, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request adds test fixtures for session and settings service mocking to the test configuration file, and updates multiple test files to register the new MockSessionService and adjust assertions to account for the additional SESSION_SERVICE registration.

Changes

Cohort / File(s) Summary
Test Configuration & Fixtures
src/lfx/tests/unit/services/conftest.py
Adds MockSessionService class with ready-state initialization and async teardown; introduces three new fixtures: mock_session_service, mock_settings_service(tmp_path) with config_dir setup, and service_manager_with_session for pre-configured manager with SESSION_SERVICE registered.
Service Manager & Integration Tests
src/lfx/tests/unit/services/test_service_manager.py, test_integration.py, test_decorator_registration.py
Updates fixtures to register MockSessionService in ServiceManager; adjusts service count assertions from 4 to 5 (or uses >= comparisons) to account for SESSION_SERVICE presence; updates import statements to include MockSessionService and related mocks.
Minimal Services Tests
src/lfx/tests/unit/services/test_minimal_services.py
Modifies LocalStorageService constructor calls from (data_dir) to (session_service, settings_service); updates storage fixture and test signatures to accept mock services instead of tmp_path; adjusts path assertions to derive expected paths from mock_settings_service.settings.config_dir.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cz/fix-services-lfx-test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added test Changes to tests and removed test Changes to tests labels Jan 19, 2026
ogabrielluiz pushed a commit that referenced this pull request Jan 19, 2026
github-merge-queue Bot pushed a commit that referenced this pull request Jan 21, 2026
* fix: Remove redundant dependencies from pyproject.toml

* feat: Refactor optional dependencies in pyproject.toml for improved organization and clarity

* feat: Update optional dependencies in pyproject.toml for enhanced functionality and organization

* feat: Consolidate dependencies in pyproject.toml for better management

* feat: Expand complete installation dependencies in pyproject.toml for comprehensive support

* new lock

* feat: Update package versions and refactor complete installation dependencies in pyproject.toml

* update lock

* feat: Update dependencies in pyproject.toml to use 'local' installation and restructure complete installation groups

* feat: Add langchain_elasticsearch dependency to elasticsearch in pyproject.toml

* feat: Add types-cachetools dependency and update version constraints for existing packages in pyproject.toml

* feat: Update pyproject.toml to change langflow-base dependency from 'local' to 'complete' installation and remove dev extra

* Update pyproject.toml to modify dependencies and improve installation structure

* refactor: Remove 'deploy' and 'dev' extras from complete installation in pyproject.toml

* add missing deps

* fix: update langchain-chroma dependency version to 0.2.6

* Remove clickhouse and pypdf from main deps

* move clickhouse

* add lock

* update lockfile

* Add utility function to convert pandas/numpy scalars to int

* Update component index

* Update component index

* fix: update no_leaks decorator to include threads for test isolation

* fix: refine model_is_empty condition for better clarity

* feat: Add pluggable services architecture in lfx and comprehensive testing (#10111)

* feat: Introduce service registration decorator and enhance ServiceManager for pluggable service discovery

- Added `register_service` decorator to allow services to self-register with the ServiceManager.
- Enhanced `ServiceManager` to support multiple service discovery mechanisms, including decorator-based registration, config files, and entry points.
- Implemented methods for direct service class registration and plugin discovery from various sources, improving flexibility and extensibility of service management.

* feat: Implement VariableService for managing environment variables

- Introduced VariableService class to handle environment variables with in-memory caching.
- Added methods for getting, setting, deleting, and listing variables.
- Included logging for service initialization and variable operations.
- Created an __init__.py file to expose VariableService in the package namespace.

* feat: Enhance LocalStorageService with Service integration and async teardown

- Updated LocalStorageService to inherit from both StorageService and Service for improved functionality.
- Added a name attribute for service identification.
- Implemented an async teardown method for future extensibility, even though no cleanup is currently needed.
- Refactored the constructor to ensure proper initialization of both parent classes.

* feat: Implement telemetry service with abstract base class and minimal logging functionality

- Added `BaseTelemetryService` as an abstract base class defining the interface for telemetry services.
- Introduced `TelemetryService`, a lightweight implementation that logs telemetry events without sending data.
- Created `__init__.py` to expose the telemetry service in the package namespace.
- Ensured robust async methods for logging various telemetry events and handling exceptions.

* feat: Introduce BaseTracingService and implement minimal TracingService

- Added `BaseTracingService` as an abstract base class defining the interface for tracing services.
- Implemented `TracingService`, a lightweight version that logs trace events without external integrations.
- Included async methods for starting and ending traces, tracing components, and managing logs and outputs.
- Enhanced documentation for clarity on method usage and parameters.

* feat: Add unit tests for service registration decorators

- Introduced a new test suite for validating the functionality of the @register_service decorator.
- Implemented tests for various service types including LocalStorageService, TelemetryService, and TracingService.
- Verified behavior for service registration with and without overrides, ensuring correct service management.
- Included tests for custom service implementations and preservation of class functionality.
- Enhanced overall test coverage for the service registration mechanism.

* feat: Add comprehensive unit and integration tests for ServiceManager

- Introduced a suite of unit tests covering edge cases for service registration, lifecycle management, and dependency resolution.
- Implemented integration tests to validate service loading from configuration files and environment variables.
- Enhanced test coverage for various service types including LocalStorageService, TelemetryService, and VariableService.
- Verified behavior for service registration with and without overrides, ensuring correct service management.
- Ensured robust handling of error conditions and edge cases in service creation and configuration parsing.

* feat: Add unit and integration tests for minimal service implementations

- Introduced comprehensive unit tests for LocalStorageService, TelemetryService, TracingService, and VariableService.
- Implemented integration tests to validate the interaction between minimal services.
- Ensured robust coverage for file operations, service readiness, and exception handling.
- Enhanced documentation within tests for clarity on functionality and expected behavior.

* docs: Add detailed documentation for pluggable services architecture and usage

* feat: Add example configuration file for Langflow services

* docs: Update PLUGGABLE_SERVICES.md to enhance architecture benefits section

- Revised the documentation to highlight the advantages of the pluggable service system.
- Replaced the migration guide with a detailed overview of features such as automatic discovery, lazy instantiation, dependency injection, and lifecycle management.
- Clarified examples of service registration and improved overall documentation for better understanding.

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* [autofix.ci] apply automated fixes (attempt 3/3)

* test(services): improve variable service teardown test with public API assertions

* docs(pluggable-service-layer): add docstrings for service manager and implementations

* Update component index

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

* test: Standardize service mocking with shared pytest fixtures for reliable test isolation (#11350)

* refactor: Replace aiofile with aiofiles for async file operations (#11351)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

* fix: update dependencies for backwards compatibility

* update index

* [autofix.ci] apply automated fixes

* fix: update duckduckgo dependency to duckduckgo-search and remove obsolete entries

* fix: update version check to reflect lfx instead of langflow

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* feat: Add dynamic options to various starter project configurations

* [autofix.ci] apply automated fixes

* fix: Update dependencies for langchain and langchain-community to latest compatible versions

* [autofix.ci] apply automated fixes

---------

Co-authored-by: Jordan Frazier <jordan.frazier@datastax.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Cristhian Zanforlin Lousa <cristhian.lousa@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test Changes to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant