v0.1.0
- Added Databricks Connect fixture. A new fixture named
sparkhas been added to the codebase, providing a Databricks Connect Spark session for testing purposes. The fixture requires thedatabricks-connectpackage to be installed and takes aWorkspaceClientobject as an argument. It first checks if acluster_idis present in the environment, and if not, it skips the test and raises a message. The fixture then ensures that the cluster is running and attempts to import theDatabricksSessionclass from thedatabricks.connectmodule. If the import fails, it skips the test and raises a message. This new fixture enables easier testing of Databricks Connect functionality, reducing boilerplate code required to set up a Spark session within tests. Additionally, a newis_in_debugfixture has been added, although there is no further documentation or usage examples provided for it. - Added
make_*_permissionsfixtures. In this release, we have added new fixtures to the pytester plugin for managing permissions in Databricks. These fixtures includemake_alert_permissions,make_authorization_permissions,make_cluster_permissions,make_cluster_policy_permissions,make_dashboard_permissions,make_directory_permissions,make_instance_pool_permissions,make_job_permissions,make_notebook_permissions,make_pipeline_permissions,make_query_permissions,make_registered_model_permissions,make_repository_permissions,make_serving_endpoint_permissions,make_warehouse_permissions,make_workspace_file_permissions, andmake_workspace_file_path_permissions. These fixtures allow for easier testing of functionality that requires managing permissions in Databricks, and are used for managing permissions for various Databricks resources such as alerts, authorization, clusters, cluster policies, dashboards, directories, instance pools, jobs, notebooks, pipelines, queries, registered models, repositories, serving endpoints, warehouses, and workspace files. Additionally, a newmake_notebook_permissionsfixture has been introduced in thetest_permissions.pyfile for integration tests, which allows for more comprehensive testing of the IAM system's behavior when handling notebook permissions. - Added
make_catalogfixture. A new fixture,make_catalog, has been added to the codebase to facilitate testing with specific catalogs, ensuring isolation and reproducibility. This fixture creates a catalog, returns its information, and removes the catalog after the test is complete. It can be used in conjunction with other fixtures such asws,sql_backend, andmake_random. The fixture is utilized in the updatedtest_catalog_fixtureintegration test function, which now includes new argumentsmake_catalog,make_schema, andmake_table. These fixtures create catalog, schema, and table objects, enabling more comprehensive testing of the catalog, schema, and table creation functionality. Please note that catalogs created using this fixture are not currently protected from being deleted by the watchdog. - Added
make_catalog,make_schema, andmake_tablefixtures (#33). In this release, we have updated thedatabricks-labs-blueprintpackage dependency todatabricks-labs-lsql~=0.10and added several fixtures to the codebase to improve the reliability and maintainability of the test suite. We have introduced three new fixturesmake_catalog,make_schema, andmake_tablethat are used for creating and managing test catalogs, schemas, and tables, respectively. These fixtures enable the creation of arbitrary test data and simplify testing by allowing predictable and consistent setup and teardown of test data for integration tests. Additionally, we have added several debugging fixtures, includingdebug_env_name,debug_env,env_or_skip, andsql_backend, to aid in testing DataBricks features related to SQL, environments, and more. Themake_udffixture has also been added for testing user-defined functions in DataBricks. These new fixtures and methods will assist in testing the project's functionality and ensure that the code is working as intended, making the tests more maintainable and easier to understand. - Added
make_clusterdocumentation. Themake_clusterfixture has been updated with new functionality and improvements. It now creates a Databricks cluster with specified configurations, waits for it to start, and cleans it up after the test, returning a function to create clusters. Thecluster_idattribute is accessible from the returned object. The fixture accepts several keyword arguments:single_nodeto create a single-node cluster,cluster_nameto specify a cluster name,spark_versionto set the Spark version, andautotermination_minutesto determine when the cluster should be automatically terminated. Thewsandmake_randomparameters have been removed. The commit also introduces a new test function,test_cluster, that creates a single-node cluster and outputs a message indicating the creation. Documentation for themake_clusterfunction has been added, and themake_cluster_policyfunction remains unchanged. - Added
make_experimentfixture. In this release, we introduce themake_experimentfixture in thedatabricks.labs.pytester.fixtures.mlmodule, facilitating the creation and cleanup of Databricks Experiments for testing purposes. This fixture accepts optionalpathandexperiment_nameparameters and returns adatabricks.sdk.service.ml.CreateExperimentResponseobject. Additionally,make_experiment_permissionshas been added for managing experiment permissions. In thepermissions.pyfile, the_make_permissions_factoryfunction replaces the previous_make_redash_permissions_factory, enhancing the code's maintainability and extensibility. Furthermore, amake_experimentfixture has been added to theplugin.pyfile for creating experiments with custom names and descriptions. Lastly, atest_experimentsfunction has been included in thetests/integration/fixturesdirectory, utilizingmake_group,make_experiment, andmake_experiment_permissionsfixtures to create experiments and assign group permissions. - Added
make_instance_pooldocumentation. In this release, themake_instance_poolfixture has been updated with added documentation, and the usage example has been slightly modified. The fixture now accepts optional keyword arguments for the instance pool name and node type ID, with default values set for each. Themake_randomfixture is still required for generating unique names. Additionally, a new function,log_workspace_link, has been updated to accept a new parameteranchorfor controlling the inclusion of an anchor (#) in the generated URL. New test functionstest_instance_poolandtest_cluster_policyhave been added to enhance the integration testing of the compute system, providing more comprehensive coverage for instance pools and cluster policies. Furthermore, documentation has been added for themake_instance_poolfixture. Lastly, three test functions,test_cluster,test_instance_pool, andtest_job, have been removed, but the setup functions for these tests are retained, indicating a possible streamlining of the codebase. - Added
make_jobdocumentation. Themake_jobfixture has been updated with additional arguments and improved documentation. It now acceptsnotebook_path,name,spark_conf, andlibrariesas optional keyword arguments, and can accept any additional arguments to be passed to theWorkspaceClient.jobs.createmethod. If nonotebook_pathortasksargument is provided, a random notebook is created and a single task with a notebook task is run using the latest Spark version and a single worker cluster. The fixture has been improved to manage Databricks jobs and clean them up after testing. Additionally, documentation has been added for themake_jobfunction and thetest_jobfunction in the test fixtures file. Thetest_jobfunction, which created a job and logged its creation, has been removed, and thetest_clusterandtest_pipelinefunctions remain unchanged. Theosmodule is no longer imported in this file. - Added
make_modelfixture. A new pytest fixture,make_model, has been added to the codebase for the open-source library. This fixture facilitates the creation and automatic cleanup of Databricks Models during tests, returning aGetModelResponseobject. The optionalmodel_nameparameter allows for customization, with a default value ofdummy-*. Themake_modelfixture can be utilized in conjunction with other fixtures such asws,make_random, andmake_registered_model_permissions, streamlining the testing of model-related functionality. Additionally, a new test function,test_models, has been introduced, utilizingmake_model,make_group, andmake_registered_model_permissionsfixtures to test model management within the system. This new feature enhances the library's testing capabilities, making it easier to create, configure, and manage models and related resources during test execution. - Added
make_pipelinefixture. A new fixture namedmake_pipelinehas been added to the project, which facilitates the creation and cleanup of a Delta Live Tables Pipeline after testing. This fixture is added to thecompute.pyfile and takes optional keyword arguments such asname,libraries, andclusters. It generates a random name, creates a disposable notebook with random libraries, and creates a single node cluster with 16GB memory and local disk if these arguments are not provided. The fixture returns a function to create pipelines, resulting in aCreatePipelineResponseinstance. Additionally, a new integration test has been added to test the functionality of this fixture, and it logs information about the created pipeline for debugging and inspection purposes. This new fixture improves the testing capabilities of the project, allowing for more robust and flexible tests of pipeline creation and management. - Added
make_queryfixture. In this release, we have added a new fixture calledmake_queryto the plugin module for the Redash integration. This fixture creates aLegacyQueryobject for testing query-related functionality in a controlled environment. It can be used in conjunction with themake_userandmake_query_permissionsfixtures to test query permissions for a specific user. Themake_queryfixture generates a random query name, creates a table, and uses thews.queries_legacy.createmethod to create the query. The query is then deleted using thews.queries_legacy.deletemethod after the test is completed. This fixture is utilized in thetest_permissions_for_redashfunction, which creates a user and a query, and then sets the permission level for the query for the created user using themake_query_permissionsfixture. This enhancement improves the testing capabilities of the Pytester framework for projects that utilize Redash. - Added
make_schemafixture. A newmake_schemafixture has been added to the open-source library to improve schema management and testing. This fixture creates a schema with an optional catalog name and a schema name, which defaults to a random string. The fixture cleans up the schema after the test is complete and returns an instance ofSchemaInfo. It can be used in conjunction with other fixtures such asmake_tableandmake_udffor easier testing and setup of schemas. Additionally, themake_schemafixture includes a new keyword-only argumentlog_workspace_linkto log a link to the created schema in the Databricks workspace. Themake_catalogfixture has also been updated to include thelog_workspace_linkargument for logging links to created catalogs. These changes enhance the testability of the code and provide better catalog and schema management in the Databricks workspace. - Added
make_serving_endpointfixture. A newmake_serving_endpointfixture has been added to the codebase, located inbaseline.py,ml.py, andplugin.pyfiles, andtests/integration/fixtures/test_ml.py. This fixture enables the creation and deletion of Databricks Serving Endpoints, handling any potential DatabricksError exceptions during teardown. It also creates a model for a small workload size and returns aServingEndpointDetailedobject. Themake_serving_endpoint_permissionsfixture is introduced as well, creating serving endpoint permissions for a specified object ID, permission level, and group name. New tests have been implemented to demonstrate the usage of these fixtures, showing how to create serving endpoints, grant query permissions to a group, and test the endpoint. Additionally, updates have been made to the README.md file to include documentation for the new fixtures. - Added
make_storage_credentialfixture. In this release, we have added a new fixture calledmake_storage_credentialto our testing utilities. This fixture creates a storage credential with configurable parameters such as credential name, Azure service principal information, AWS IAM role ARN, and read-only status. It can be used to create either an Azure or AWS storage credential, depending on the provided parameters, and removes the created credential after the test. This fixture is implemented inplugin.pyand is added to the existing list of fixtures for consistent and easy-to-use testing setup. Additionally, we have introduced an integration test calledtest_storage_credentialin the test catalog for fixtures. This test utilizes the newmake_storage_credentialfixture and verifies the functionality of creating a storage credential and the integration between the system and storage services. These new additions will make it easier to write tests that require access to storage resources and improve the efficiency and ease of testing and developing new features in the codebase. - Added
make_tablefixture. In this release, we've added themake_tablefixture to simplify testing operations on tables and catalogs. This fixture creates a table with a given catalog and schema name, CTAS statement, and properties. It can create the table as a non-delta or delta table, external table with CSV or Delta location, or a view, and allows overriding the storage location. Additionally, we've updated the fixture to include new parameters and functionality, such as logging a workspace link for the created table and specifying the catalog and schema where the table will be created. The fixture now also includes new functions for creating and casting columns in the table. After the test, the fixture automatically removes the created table. This release aims to provide a more customizable and convenient way to test table operations. - Added
make_udffixture. Themake_udffixture has been added to facilitate the creation and removal of User-Defined Functions (UDFs) for testing purposes. This fixture creates a UDF with optional parameters to specify catalog, schema, name, and Hive UDF creation. It returns an instance ofdatabricks.sdk.service.catalog.FunctionInfo. The UDF is removed after the test. This feature is utilized in the newtest_make_some_udfsintegration test, where it creates two UDFs in a schema within the Hive metastore, one with and one without Hive support. Additionally, thetest_create_viewtest is now skipped, and thetest_table_fixturetest remains unchanged. This change improves the ability to test UDFs within the Hive metastore, and allows for more comprehensive testing by creating UDFs programmatically. - Added
make_warehousefixture. A newmake_warehousefixture has been added to the test suite, which allows for the creation and customization of a Databricks warehouse for testing purposes. The fixture accepts optional keyword arguments such aswarehouse_name,warehouse_type,cluster_size,max_num_clusters, andenable_serverless_compute, allowing users to configure the warehouse's properties. It returns a function that creates a warehouse using the provided parameters and handles cleanup after the test is complete. Additionally, a corresponding test functiontest_warehouse_has_remove_after_taghas been added to verify that a newly created warehouse has the expectedRemoveAftertag, facilitating automated testing and resource management. This enhancement expands the testing capabilities of the plugin and provides a more streamlined approach to testing functionality related to Databricks warehouses. - Added ability to specify custom SQL in
make_query. Themake_queryfixture has been updated to allow for greater customization in testing, with the addition of a newquerykeyword argument. This parameter enables users to specify a custom SQL query to be stored and executed, with the default value beingSELECT * FROM <newly created random table>. The fixture continues to create and remove theLegacyQueryobject, making it user-friendly. With this enhancement, users have increased flexibility to tailor their tests to specific needs, providing more targeted and precise testing outcomes. - Added documentation for
make_cluster_policy. In this release, we introduce new features to enhance testing and managing Databricks cluster policies and workspace link logging in your project. We've added themake_cluster_policyfixture, which simplifies the creation and deletion of cluster policies using a specified workspace. This fixture returns aCreatePolicyResponseinstance and can be used within test functions. Additionally, we've developed thelog_workspace_linkfixture, which constructs and logs a workspace link for debugging and tracking purposes. Themake_cluster_policyfunction is also introduced in theplugin.pyfile, enabling users to manage and test Databricks cluster policies using the pytester framework. To ensure proper functionality, thetest_compute.pyfile includes a test function formake_cluster_policy. These improvements will help streamline testing processes and enhance the overall user experience. - Added documentation for
make_groupandmake_user. In this release, we have introduced themake_groupandmake_userfixtures to manage Databricks workspace groups and users, respectively. Themake_groupfixture allows you to create groups with specified members, roles, and entitlements, handling eventual consistency issues and waiting for group provisioning if required. Themake_userfixture creates a user and deletes it after the test, handling naming conflicts by retrying the creation process for 30 seconds. Both fixtures return instances ofGroupandUser, respectively, and have been documented in the README.md with usage examples. Additionally, we have introduced a built-in logger that traces entity creation and deletion through links in the Databricks Workspace UI, and added documentation for themake_groupandmake_userfunctions using thegen-readme.pyscript. The release also includes updates to theconftest.pyfile in thetests/integrationdirectory, importing thefixturefunction frompytestand theinstall_loggerandloggingmodules fromdatabricks.labs.blueprint.loggerto improve documentation and configure logging for the project. - Added documentation for
make_notebook,make_directory, andmake_repo. Themake_notebook,make_directory, andmake_repofixtures have been updated with new functionality and improved documentation in this release. These fixtures are used in tests to manage Databricks notebooks, directories, and repos respectively, and they now return functions that create resources with specified parameters. Themake_notebookfixture now includes optional keyword arguments forpath,content,language,format, andoverwrite, and returns anos.PathLikeobject that will be automatically deleted after the test is complete. Themake_directoryfixture now includes an optional keyword argument forpath, and themake_repofixture now includes optional keyword arguments forurl,provider, andpath. These fixtures simplify the process of creating and managing Databricks resources in tests and help ensure that resources are properly cleaned up after each test is complete. The commit also includes documentation for the new functionality and integration tests for these fixtures. - Added documentation for
make_secret_scopeandmake_secret_scope_acl. In this release, documentation has been added for two new functions,make_secret_scopeandmake_secret_scope_acl, which are used for creating and managing secret scopes and their associated access control lists (ACLs) in a Databricks Workspace. Themake_secret_scopefunction creates a new secret scope with a unique name generated using a random name generator, and automatically deletes the scope after the test is complete. Themake_secret_scope_aclfunction manages ACLs for secret scopes, defining permissions for principals (users or groups) on specific secret scopes. Three new test functions have also been added to test the functionality of creating secret scopes and managing their ACLs using these new functions. Additionally, type hints have been added to the package to support PEP 561. Overall, these changes improve the documentation and testing of the project, making it easier for developers to understand and use these new functions for managing secret scopes and their ACLs in a Databricks Workspace. - Added documentation update on
make fmt(#34). In this release, themake fmtcommand in the documentation has been updated to include an additional step that runs thegen-readme.pyscript before executinghatch run fmt. This new script generates or updates the README file with detailed documentation on various PyTest fixtures available in the Python Testing for Databricks project. A newFixturedataclass has been introduced to represent a fixture's metadata, and thedatabricks.labs.pytester.fixtures.pluginmodule is used to discover all fixtures. TheFIXTURESsection in the README.md file has been updated with the new documentation, which includes information on the purpose, parameters, return values, and usage examples for each fixture. Thetestandlinttargets in the Makefile remain unchanged. Please note that this project is not officially supported by Databricks. - Added downstream testing. In this enhancement, we have implemented downstream testing in our CI/CD pipeline through the introduction of a new GitHub Actions workflow called "downstreams.yml." This workflow runs tests when pull requests are opened, synchronized, or checked during a merge group, and on pushes to the main branch. The job compatibility is set up to run on the latest version of Ubuntu, and it includes steps to checkout the code with a full fetch depth, install Python, install the toolchain, and run the downstreams test suite using the databrickslabs/sandbox/downstreams action. The downstreams matrix includes the blueprint, lsql, ucx, and remorph repositories in the databrickslabs organization. The GITHUB_TOKEN environment variable is used for authentication. This improvement will help ensure that our codebase remains stable and functional as we continue to develop and release new features.
- Added note on UCX project. In the 2024 release, the open-source library has undergone significant updates, incorporating the UCX project into its ecosystem. UCX, an open-source project providing a unified communication layer for various high-performance computing (HPC) platforms, enhances the library's functionality, particularly in automated migrations and static code analysis. The library, developed as part of the Unity Catalog Automated Migrations project, has also added new authors and maintainers, including Vuong Nguyen, Lars George, Cor Zuurmond, Andrew Snare, Pritish Pai, and removed Liran Bareket and Vuong Nguyen, indicating potential new contributions and teams involved. The logging section has also been improved, based on years of debugging integration tests for Databricks and its ecosystem, simplifying integration testing with Databricks for other projects.
- Added support for
.envfiles (#36). In this change, we have added support for.envfiles to the open-source library, allowing for local debugging and integration tests in IDEs. A newdebug_env_namefixture has been introduced, which enables specifying the name of the debug environment with a default value of.env. If there are security concerns about using.envfiles, a~/.databricks/debug-env.jsonfile can be used instead. Additionally, we have updated thegen-readme.pyscript and theFixtureclass to improve documentation and provide information about the relationships between fixtures and.envfiles. Thedebug_envfixture has been added to read adebug-env.jsonfile if the code is running in debug mode, and theenv_or_skipfixture has been updated to skip tests if required environment variables are not set. These changes improve the testing capabilities of the library, allowing for easier management and integration of environment variables in tests. - Added supporting documents. In this release, we introduce a new changelog file for the project, versioned at 0.0.0, to record notable changes over time. Additionally, we have added a CODEOWNERS file, designating @nfx as the default code owner for all files in the repository, and a CONTRIBUTING.md file that provides detailed guidelines for contributing to the project. The CONTRIBUTING.md file covers a wide range of topics, including first principles, change management, code organization, adding new fixtures, common mypy error fixes, integration testing infrastructure, local setup, first contribution, and troubleshooting. These additions aim to improve code quality, maintainability, and collaboration for the project's developers and users.
- Added telemetry tracking. A new telemetry tracking feature has been implemented in the project with the addition of the
with_user_agent_extramethod in the "init.py" file. This method, sourced from the "databricks.sdk.core" package, enables the attachment of an extra user agent string to HTTP requests, which includes the version of thepytesterproject. The "about.py" file's__version__variable is utilized to ensure the specific version of thepytesterproject is incorporated in the user agent string. This enhancement allows for the tracking of project usage and statistics through user agents, providing valuable insights for future development and improvements. - Added unit testing for test fixtures. In this release, we have added comprehensive unit tests for various entities in our codebase, such as alerts, authorization permissions, catalog, cluster, cluster policies, dashboard permissions, directories, experiments, feature table permissions, groups, instance pools, instance pool permissions, jobs, job permissions, lakeview dashboard permissions, models, notebooks, notebook permissions, pipelines, pipeline permissions, queries, query permissions, registered model permissions, repos, repo permissions, secret scopes, secret scope ACLs, serving endpoints, serving endpoint permissions, storage credentials, UDFs, users, warehouses, warehouse permissions, workspace file path permissions, and workspace file permissions. Additionally, we have updated fixtures such as sql_backend, workspace_library, debug_env, and product_info with tests and provided examples on how to use these fixtures in the code. We have also updated our configuration files to improve code quality, maintainability, and reliability, including updating the version of mypy, adding the unit package to the known-first-party modules in isort configuration, and updating the ignore list for pylint. Furthermore, we have added a new
unwrap.pyfile to thedatabricks/labs/pytester/fixturesdirectory to support unit testing of pytest fixtures. We have also added unit tests for test fixtures in various files, ensuring that the fixtures behave as expected, thereby improving the reliability and stability of the codebase. Lastly, we have added a new unit test file for testing catalog functionality, specifically for themake_tablefunction, which creates a new managed table with a specified schema and table type. - Bump unit testing coverage. This commit enhances the unit testing coverage and improves the overall code quality of the open-source library. Several changes have been introduced, including the addition of new fixtures
sql_backend,sql_exec, andsql_fetch_allfor testing SQL-related functionality in the Databricks platform. These fixtures are demonstrated in the newly addedrandom_stringtest case. The commit also introduces a new sectionexclude_alsounder the "[tool.mypy]" section in the pyproject.toml file, which provides more precise control over the lines checked during mypy type checking. Furthermore, the environment.py file has been removed, and several SQL backend and test resource purge time-related fixtures have been deleted, resulting in increased unit testing coverage. Additionally, thecatalog.pyandcompute.pyfiles in thedatabricks/labs/pytester/fixturesdirectory have been updated to improve resource management and ensure proper handling after tests are executed. Thepermissions.pyfile has been modified to remove thesql/prefix from permission paths for dashboards, alerts, and queries, simplifying the permission hierarchy in the tests. Theplugin.pyfile has been updated to reorganize SQL and environment-related functions, making them more modular and maintainable. Finally, new utility fixtureswatchdog_remove_afterandwatchdog_purge_suffixhave been added in thewatchdog.pyfile to manage and purge test objects as needed, and a new file,.env, has been added to thetests/unit/fixtures/directory to provide consistent testing conditions. These changes contribute to a better testing environment and improved overall project quality. - Prettify fixture documentation (#35). In this release, the documentation of the
wsfixture in the Databricks testing project has been significantly enhanced in the README file. Thewsfixture now has more comprehensive documentation, including its purpose, usage example, and the fact that it is built on top of other fixtures. Additionally, the Fixture class in the gen-readme.py script has been improved for better readability and clarity. Themake_randomfunction in the baseline.py file has been refactored for improved documentation and clarity, with updated usage examples and the removal of a deprecatedReturnssection. These changes aim to provide clearer and more comprehensive documentation for users, making it easier to understand and utilize the features effectively. - Updated README.md. In this update, we have added several PyTest fixtures to enhance testing capabilities in the Databricks workspace. These fixtures include
make_warehouse_permissions,make_lakeview_dashboard_permissions,log_workspace_link,make_dashboard_permissions,make_alert_permissions,make_query_permissions,make_experiment_permissions,make_registered_model_permissions,make_serving_endpoint_permissions, andmake_feature_table_permissions. These additions enable easier testing of various functionalities and linking within the workspace. Furthermore, we have included themake_authorization_permissionsfixture to facilitate testing of authorization functionalities. To aid in debugging, we have updated theLoggingsection with thedebug_env_nameanddebug_envfixtures. Lastly, we have added theworkspace_libraryfixture for testing library-related functionalities in the workspace. These changes improve the overall testing experience and enable more comprehensive testing within the Databricks workspace. - Updated pytest requirement from ~=8.1.0 to ~=8.3.3 (#31). In this pull request, we update the pytest requirement from version 8.1.0 to 8.3.3 in our pyproject.toml file. This update includes several bug fixes and improvements for our testing framework, such as avoiding the calling of properties during fixture discovery, fixing the issue of not displaying assertion failure differences with the
--import-mode=importliboption in pytest 8.1 and above, and addressing a regression that caused mypy to fail. Additionally, we fix typing compatibility with Python 3.9 or less by replacingtyping.Selfwithtyping_extensions.Self. This update also ensures consistent path handling across environments by fixing an issue with backslashes being incorrectly converted in nodeid paths on Windows.
Dependency updates:
- Updated pytest requirement from ~=8.1.0 to ~=8.3.3 (#31).
Contributors: @nfx, @dependabot[bot]