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

Mark tests for async test suite more accurately #3180

Merged
merged 4 commits into from
Jan 10, 2024

Conversation

fselmo
Copy link
Collaborator

@fselmo fselmo commented Dec 29, 2023

What was wrong?

  • All async tests need the @pytest.mark.asyncio decorator to be picked up by pytest-asyncio. This already marks them as asyncio tests, so we should use the -m option to call them. Looking for "async" in the test name with the-k option caused us to miss some tests that we didn't name with "async" in them in the async test suite.

  • Note to any reviewers: Be sure to check that the selected number in one test run equals the deselected number in the other.

Todo:

Cute Animal Picture

20240108_191245

@fselmo fselmo changed the title Run asyncio tests more efficiently Mark async tests more explicitly Dec 29, 2023
@fselmo fselmo changed the title Mark async tests more explicitly Mark tests for async test suite more accurately Dec 29, 2023
@fselmo fselmo marked this pull request as ready for review December 29, 2023 22:04
tox.ini Outdated
core: pytest {posargs:tests/core -k "not async"}
core_async: pytest {posargs:tests/core -k async}
core: pytest {posargs:tests/core -m "not asyncio" -k "not async"}
core_async: pytest {posargs:tests/core -k "asyncio or async"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should asyncio be part of the mark expression flag? I think this will find any test names containing asyncio or async (which in turn finds anything that would include asyncio I believe).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, good catch. I think it should be the opposite of the previous. Will change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this approach needs to be revised actually... I don't believe the -m and -k work well enough together. We may just have to run asyncio marked tests and the opposite as:

  • pytest tests/core -m asyncio: run tests that are actually asynchronous in nature
  • pytest tests/core -m "not asyncio": run all other tests, including those that may involve async classes but aren't asynchronous in nature (e.g. testing some static, non-asynchronous, property of some asynchronous class)

fselmo added a commit to fselmo/web3.py that referenced this pull request Jan 10, 2024
fselmo added a commit to fselmo/web3.py that referenced this pull request Jan 10, 2024
@fselmo fselmo force-pushed the run-asyncio-tests-more-efficiently branch from 8ea55be to b5d8fca Compare January 10, 2024 20:13
fselmo added a commit to fselmo/web3.py that referenced this pull request Jan 10, 2024
fselmo added a commit to fselmo/web3.py that referenced this pull request Jan 10, 2024
fselmo added a commit to fselmo/web3.py that referenced this pull request Jan 10, 2024
@fselmo fselmo force-pushed the run-asyncio-tests-more-efficiently branch from aa99744 to 493fa0a Compare January 10, 2024 20:22
- All async tests need the ``@pytest.mark.asyncio`` decorator to be picked up by pytest-asyncio. This already marks them as asyncio tests, so we should use the ``-m`` option to call them as well as looking for "async" in the test name with the``-k`` option. This is necessary since some async tests only test for properties and aren't actually asynchronous but we want to consider them as part of the async test suite (e.g. testing some attribute on the AsyncHttpProvider).

- Reviewers, be sure to check that the selected number in one test run equals the deselected number in the other.
@fselmo fselmo force-pushed the run-asyncio-tests-more-efficiently branch from 493fa0a to dbfe191 Compare January 10, 2024 20:38
Copy link
Contributor

@reedsa reedsa left a comment

Choose a reason for hiding this comment

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

Good to see the marker flag, way more robust than relying on the test name itself.

@kclowes
Copy link
Collaborator

kclowes commented Jan 10, 2024

Note to any reviewers: Be sure to check that the selected number in one test run equals the deselected number in the other

I looked at the py310-core and py310-core_async tests, and it doesn't look like the numbers are quite adding up? I could be wrong though

  passed skipped deselected xfailed warnings
sync 2035 14 676 5 7
async 667 2 2054 7 3

@fselmo
Copy link
Collaborator Author

fselmo commented Jan 10, 2024

I looked at the py310-core and py310-core_async tests, and it doesn't look like the numbers are quite adding up? I could be wrong though

Oh weird. Where is that? I'm seeing the opposite numbers from each other (sync vs async).

@kclowes
Copy link
Collaborator

kclowes commented Jan 10, 2024

Oh, I see what you're talking about. I think we're good. The numbers I was looking at are at the bottom in the output after the run. sync, and async

Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

LGTM! Much cleaner! 🧹

@fselmo
Copy link
Collaborator Author

fselmo commented Jan 10, 2024

Oh, I see what you're talking about. I think we're good. The numbers I was looking at are at the bottom in the output after the run. sync, and async

ohh I see... yeah the skipped and xfailed ones, etc, skew the numbers a bit or at least make it a bit more confusing to compare 👍🏼

@fselmo fselmo merged commit ed44515 into ethereum:main Jan 10, 2024
99 checks passed
fselmo added a commit that referenced this pull request Jan 10, 2024
@fselmo fselmo deleted the run-asyncio-tests-more-efficiently branch January 10, 2024 22:01
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.

3 participants