Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#58 Made the pytest-slc plugin using the pyexasol_connection #59

Merged
merged 7 commits into from
Sep 23, 2024

Conversation

ahsimb
Copy link
Contributor

@ahsimb ahsimb commented Sep 20, 2024

closes #58

@ahsimb ahsimb added the bug Unwanted / harmful behavior label Sep 20, 2024
@ahsimb ahsimb requested a review from ckunki September 20, 2024 13:07
@ahsimb ahsimb self-assigned this Sep 20, 2024
bucketfs_path=bucketfs_path,
language_alias=slc_builder.language_alias)
deployer.run(container_file=export_slc, alter_system=True, allow_override=True)
def func(language_alias: str) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, you changed it to that, such that we can isolate the aliases per test, if it necessary. I could assume, in case of the deployer tests and the extension tests that could be necessary. Or, did you think of a different reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the motivation is described in the related ticket #58:

If an extension test uses both pyexasol_connection fixture from the pytest-extension and upload_slc fixture from the pytest-slc then the container may not get activated for the pyexasol_connection session if the pyexasol_connection fixture is created first. To make sure this doesn't happen the pytest-slc should depend on the pytest-extension and use its pyexasol_connection fixture instead of creating its own connection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I have some more questions:

  1. Could we make the function func use the language_alias that is already known to the slc_builder?
  2. Why does the fixture return a function instead of just uploading the SLC?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question was related to the function and not the Pyexasol connection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to take the language_alias from the LanguageContainerBuilder. As we found, the language_alias is not actually required to build a language container; it is only for testing it, which we don't do. So it was removed from the LanguageContainerBuilder. But we do need it for the container deployer. Hence is the upload_slc function. We can provide the language_alias there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But good point , maybe we need a fixture that returns a function that activates the SLC for a connection

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to take the language_alias from the Builder ... language_alias is not actually required to build a language container ... But for the deployer. ...

Ah - very good, thank you!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decision:

  • Rename fixture upload_slc to deploy_slc
  • Add fixture deployed_slc which uses a dummy fixture for alias which needs be overwritten by the extension
  • the function returned by deploy_slc fixture uses a state variable stored in deploy_slc fixture to upload the slc only once and only activate it in subsequent calls

pytest-slc/doc/changes/changes_0.3.0.md Outdated Show resolved Hide resolved
pytest-slc/doc/changes/changes_0.3.0.md Outdated Show resolved Hide resolved
bucketfs_path=bucketfs_path,
language_alias=slc_builder.language_alias)
deployer.run(container_file=export_slc, alter_system=True, allow_override=True)
def func(language_alias: str) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the motivation is described in the related ticket #58:

If an extension test uses both pyexasol_connection fixture from the pytest-extension and upload_slc fixture from the pytest-slc then the container may not get activated for the pyexasol_connection session if the pyexasol_connection fixture is created first. To make sure this doesn't happen the pytest-slc should depend on the pytest-extension and use its pyexasol_connection fixture instead of creating its own connection.

@@ -24,7 +24,7 @@ def assert_udf_running(conn: pyexasol.ExaConnection):
with temp_schema(conn) as schema:
udf_name = 'TEST_UDF'
udf_create_sql = (
f'CREATE OR REPLACE {{LANGUAGE_ALIAS}} SCALAR SCRIPT "{{schema}}"."{{udf_name}}"() '
f'CREATE OR REPLACE {LANGUAGE_ALIAS} SCALAR SCRIPT "{{schema}}"."{{udf_name}}"() '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% sure, but shouldn't all parameters be enclosed only in single braces to allow f-string substitution?

Suggested change
f'CREATE OR REPLACE {LANGUAGE_ALIAS} SCALAR SCRIPT "{{schema}}"."{{udf_name}}"() '
f'CREATE OR REPLACE {LANGUAGE_ALIAS} SCALAR SCRIPT "{schema}"."{udf_name}"() '

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a piece of code, which itself uses f-strings. This is the case for the schema and udf_name. In this code, the LANGUAGE_ALIAS is a constant which we insert externally, also using an f-string. Basically, there is an external and internal f-string.

bucketfs_path=bucketfs_path,
language_alias=slc_builder.language_alias)
deployer.run(container_file=export_slc, alter_system=True, allow_override=True)
def func(language_alias: str) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I have some more questions:

  1. Could we make the function func use the language_alias that is already known to the slc_builder?
  2. Why does the fixture return a function instead of just uploading the SLC?

ckunki
ckunki previously approved these changes Sep 23, 2024
Co-authored-by: Christoph Kuhnke <[email protected]>
ckunki
ckunki previously approved these changes Sep 23, 2024
ckunki
ckunki previously approved these changes Sep 23, 2024
Comment on lines 18 to 19
Here, we override the default `language_alias` fixture providing a "meaningful" name. The language container will be
activated with this language alias. Note, that by default the test will run twice - once for each backend.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Here, we override the default `language_alias` fixture providing a "meaningful" name. The language container will be
activated with this language alias. Note, that by default the test will run twice - once for each backend.
The example test case overrides two fixtures that are used by fixture `deployed_slc` from this plugin:
* Fixture `language_alias` to provide a meaningful name.
* and fixture `slc_builder` to define the SLC to be used in the example test case.
The language container will be activated with value returned by fixture `language_alias`.
Note, that by default the test will run twice - once for each backend.

@ahsimb ahsimb merged commit d1dfad9 into main Sep 23, 2024
1 check passed
@ahsimb ahsimb deleted the bug/58-pytest-slc-dependency branch September 23, 2024 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unwanted / harmful behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pytest-slc should use the pyexasol_connection fixture from the pytest-extension
3 participants