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

Tests: Fixture implementation duplicated between deprecated manage/tests/pytest_fixtures.py and tools/pytest_fixtures/ #6612

Open
GeigerJ2 opened this issue Nov 15, 2024 · 7 comments

Comments

@GeigerJ2
Copy link
Contributor

For instance, aiida_localhost in manage/tests/pytest_fixtures.py:

@pytest.fixture(scope='function')
def aiida_localhost(aiida_computer_local) -> Computer:
"""Return a :class:`aiida.orm.computers.Computer` instance representing localhost with ``core.local`` transport.
Usage::
def test(aiida_localhost):
assert aiida_localhost.transport_type == 'core.local'
:return: The computer.
"""
return aiida_computer_local(label='localhost')

and in tools/pytest_fixtures/orm.py:

@pytest.fixture
def aiida_localhost(aiida_computer_local) -> 'Computer':
"""Return a :class:`aiida.orm.computers.Computer` instance representing localhost with ``core.local`` transport.
Usage::
def test(aiida_localhost):
assert aiida_localhost.transport_type == 'core.local'
:return: The computer.
"""
return aiida_computer_local(label='localhost')

with manage/tests/pytest_fixtures.py being deprecated:

warn_deprecation(
'The module `aiida.manage.tests.pytest_fixtures` is deprecated, please use `aiida.tools.pytest_fixtures` instead.',
version=3,
)

Of course, we still need to keep access from the old module for now for backwards compatibility, otherwise plugins break, e.g.:

https://github.com/aiidateam/aiida-quantumespresso/blob/57e7463c5727775d6a0470a41d1aca0ec4083b9a/tests/conftest.py#L13

But rather than duplicating the source code as it seems to be done now, we should let the fixtures in manage/tests/pytest_fixtures.py call the actual implementation in tools/pytest_fixtures/orm.py. Pinging the aiida-core office @agoscinski, @unkcpz, @khsrali.

@GeigerJ2 GeigerJ2 changed the title Tests: Fixture implementation duplicated between deprecated manage/tests/pytest_fixtures.py and tools.pytest_fixtures Tests: Fixture implementation duplicated between deprecated manage/tests/pytest_fixtures.py and tools/pytest_fixtures/ Nov 15, 2024
@unkcpz
Copy link
Member

unkcpz commented Nov 15, 2024

I totally agree. I think the doc page https://aiida.readthedocs.io/projects/aiida-core/en/stable/topics/plugins.html#plugin-test-fixtures Is very helpful to show what fixtures that plugin developers can use. We may also want to add same paper for public APIs.

@danielhollas
Copy link
Collaborator

I honestly don't know if it is worth the churn to be refactoring deprecated functions. I think it is easier to let them be and eventually remove them, and only do new development in the new ones.

@unkcpz
Copy link
Member

unkcpz commented Nov 16, 2024

I guess the problem @GeigerJ2 and @khsrali had today was they made changes to new fixtures and then found changes need to apply to the deprecated one as well, correct me if I am wrong.
The problem is if it is marked as "will be deprecated", do we still need to keep it maintained? The change by pointing to only single definition sounds a good solution for me. I don't have too much experience on how to deprecate things, aiida_localhost sound like very small so it can rarely break thus may not need to change. But point to one definition can be a good practice if it is not too hard?

@agoscinski
Copy link
Contributor

I don't have too much experience on how to deprecate things

We don't have a consistent way to do it over the modules but in this case manage/tests/pytest_fixtures is anyway not public API, so we can just remove it.

@GeigerJ2
Copy link
Contributor Author

GeigerJ2 commented Nov 25, 2024

I honestly don't know if it is worth the churn to be refactoring deprecated functions. I think it is easier to let them be and eventually remove them, and only do new development in the new ones.

Yeah, I agree, that's why I only made the issue so far, not a PR :D Though, it should be quite quick. Just remove the source code there and import from the more recent modules instead.

I guess the problem @GeigerJ2 and @khsrali had today was they made changes to new fixtures and then found changes need to apply to the deprecated one as well, correct me if I am wrong.

Not really changing anything, but I wanted to look at the fixture implementation, and global search in VS Code yielded two definitions, which confused me.

@danielhollas
Copy link
Collaborator

We don't have a consistent way to do it over the modules but in this case manage/tests/pytest_fixtures is anyway not public API, so we can just remove it.

Regardless of a definition of a public API, these fixtures are widely used in the AiiDA ecosystem, so we shouldn't remove them just yet IMO, not until a few releases. The new fixtures were only introduced in v2.6 so it'll be a while until everybody catches up.

@danielhollas
Copy link
Collaborator

Yeah, I agree, that's why I only made the issue so far, not a PR :D

👍 😄

Though, it should be quite quick. Just remove the source code there and import from the more recent modules instead.

To clarify, my main concern was not really about the time to implement it, but the fact that you would be introducing coupling between the manage and tools module, which I think is not desireable. Also, once you have a single source of truth, if you would change it, it would change the old fixtures as well, which might not be desireable and could break people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants