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

Adds a pytest local fixture for pulp_file #1728

Merged
merged 1 commit into from
Dec 17, 2021

Conversation

bmbouter
Copy link
Member

@bmbouter bmbouter commented Nov 22, 2021

Required PR: pulp/pulp-smash#1262

closes #9623

@pulpbot
Copy link
Member

pulpbot commented Nov 22, 2021

WARNING!!! This PR is not attached to an issue. In most cases this is not advisable. Please see our PR docs for more information about how to attach this PR to an issue.

pulpcore/tests/conftest.py Outdated Show resolved Hide resolved
pulpcore/tests/conftest.py Outdated Show resolved Hide resolved
@bmbouter
Copy link
Member Author

bmbouter commented Dec 7, 2021

To run the new test you can run: pytest -v -r sx --color=yes --pyargs pulpcore.tests.functional.api.using_plugin.test_sync

@bmbouter bmbouter force-pushed the add-aiohttp-fixture branch 6 times, most recently from 0ad113c to 12b6ea4 Compare December 8, 2021 21:34
Comment on lines 13 to 90
basic_file_fixture_gen_remote,
file_repo,
file_repo_api_client,
content_file_api_client,
async_monitor_task,
delete_orphans_pre_post,
Copy link
Member Author

Choose a reason for hiding this comment

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

I started to make these pytest autouse fixtures, but it would really take away from the explicitness of this. So I left it as-is for now.

return Path(__file__).parent / "fixtures"


@pytest.fixture
Copy link
Member Author

Choose a reason for hiding this comment

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

It wouldn't let me make this one scope="session" because pytest wouldn't run with ScopeMismatch: You tried to access the 'function' scoped fixture 'aiohttp_server' with a 'session' scoped request object, involved factories.

Copy link
Member Author

Choose a reason for hiding this comment

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

Through more discussion we decided that while it is tempting to make each fixture server a session scope, threads are light, and eventually we want to run these in parallel which would put us back into a fixture scoped webserver. So we'll leave as fixture scope now too.

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between the scopes? What difference(benefit) would it make to have this function be a different scope?

Copy link
Member Author

Choose a reason for hiding this comment

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

Session level for example causes the fixture to be run once for the whole session (all the tests) so that data is cached and read from heavily. Other fixtures though we want to be per-test, e.g. the webservers themselves (and all the fixtures that support those). https://docs.pytest.org/en/latest/how-to/fixtures.html#scope-sharing-fixtures-across-classes-modules-packages-or-session

@bmbouter bmbouter force-pushed the add-aiohttp-fixture branch 3 times, most recently from f6330c3 to e0e642a Compare December 9, 2021 21:27
@bmbouter bmbouter force-pushed the add-aiohttp-fixture branch 2 times, most recently from c6bdf81 to 5f4b3d4 Compare December 9, 2021 21:51
@bmbouter bmbouter force-pushed the add-aiohttp-fixture branch 4 times, most recently from 806e460 to 316e1f6 Compare December 13, 2021 21:29
@@ -0,0 +1 @@
from .conftest_pulp_file import * # noqa
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe, or we could just move that code here and avoid the import. The idea here was to organize the code we deliver into various submodules that then import here. It looks strange with just one of them though. Should I move the code from conftest_pulp_file here or leave as is?

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 only other imports here would be pulpcore related, maybe they could be useful.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not talking about imports. I mean
pytest_plugins = ("pulp_smash.pulp3.pytest_plugin",)
and i keep wondering how it can even work without it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it's confusing, but this installation uses the entrypoint method. That is in the setup.py now.

@bmbouter
Copy link
Member Author

Alright I think these achieve everything I'm happy with so I'm going to undraft it and leave a few comments for reviewers.

@bmbouter bmbouter marked this pull request as ready for review December 15, 2021 18:10
@bmbouter bmbouter force-pushed the add-aiohttp-fixture branch 10 times, most recently from 4121832 to e460884 Compare December 15, 2021 21:15
)


def test_ondemand_to_immediate_sync(
Copy link
Member Author

Choose a reason for hiding this comment

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

This was the original test, just now rewritten.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move the original class docs string here? Also, I know the function names are pretty descriptive, but do you think they deserve doc strings as well? I'm surprised the linter didn't throw a fit over the absence.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can add some docstrings. Also I'd like to update the content for the test that was rewritten. Let me do some of that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added some. I try to keep them short but clear.



@pytest.fixture
def file_fixture_gen_remote_ssl(
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the fixture I expect most tests to use.

return Path(__file__).parent / "fixtures"


@pytest.fixture
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between the scopes? What difference(benefit) would it make to have this function be a different scope?

@@ -0,0 +1 @@
from .conftest_pulp_file import * # noqa
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 only other imports here would be pulpcore related, maybe they could be useful.

pulpcore/tests/functional/api/using_plugin/test_sync.py Outdated Show resolved Hide resolved
)


def test_http_sync_ssl_tls_validation_defaults_to_on(
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this validate that tls validation is defaulted to on?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the remote it constructs does not specify it (that's the default part) yet it's connecting to a TLS context that is presenting a cert that will not be trusted without additional CA configuration.

Comment on lines +169 to +185
assert len(requests_record) == 1
assert requests_record[0].path == "/basic/PULP_MANIFEST"
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah this interface is so much better. Big thanks to @mdellweg for suggesting we do it this way.

@bmbouter bmbouter force-pushed the add-aiohttp-fixture branch 3 times, most recently from 49116f2 to 33e8a72 Compare December 16, 2021 17:08
MANIFEST.in Show resolved Hide resolved
@@ -0,0 +1 @@
from .conftest_pulp_file import * # noqa
Copy link
Member

Choose a reason for hiding this comment

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

I'm not talking about imports. I mean
pytest_plugins = ("pulp_smash.pulp3.pytest_plugin",)
and i keep wondering how it can even work without it.

pulpcore/tests/conftest_pulp_file.py Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

5 participants