-
Notifications
You must be signed in to change notification settings - Fork 24
Update pytest-asyncio to actually run async tests #119
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
Conversation
|
Oh right. And this is the one existing test that has always been broken but previously didn't run. Fix coming in next commit... |
| assert response.body.done | ||
|
|
||
|
|
||
| @pytest.mark.asyncio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For posterity, why wasn't this needed anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we have asyncio-mode set to auto in our configuration file, the marker can be avoided.
Relevant docs are here: https://pytest-asyncio.readthedocs.io/en/latest/reference.html#markers
In auto mode, the pytest.mark.asyncio marker can be omitted, the marker is added automatically to async test functions.
| async def test_endpoint_provider_with_url_string() -> None: | ||
| params = StaticEndpointParams( | ||
| url="https://foo.example.com/spam:8080?foo=bar&foo=baz" | ||
| url="https://foo.example.com:8080/spam?foo=bar&foo=baz" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦
|
What an adventure getting the CI to actually pass on this. Actually had to add an Ready for another look. |
nateprewitt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this overall looks great. Thanks for the deep dive @jonemo! I have one comment on the URI that we should take a look at but doesn't need to be part of this PR. Let me know your thoughts, but otherwise, this is fine to merge.
| self.scheme == other.scheme | ||
| and self.host == other.host | ||
| and self.port == other.port | ||
| and self.path == other.path | ||
| and self.query == other.query | ||
| and self.username == other.username | ||
| and self.password == other.password | ||
| and self.fragment == other.fragment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this change, but it's pointing to a couple things I would have noted on the original PR.
URI (and all of our method signatures) should start with (self, *, ...). The goal there is to ensure we only operate with keyword arguments. This provides us more flexibility in ordering on function signatures and prevents breakages with accidental ordering issues.
We should also ideally have these ordered in the constructor (and here) as they appear in the URI when formatted.
{scheme}://{username}:{password}@{host}:{port}{path}{query}{fragment}
We can handle that in a separate PR but should probably track it somewhere unless there's a strong argument with the above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My other branch is all about implementing the interfaces as stated in the spec. This PR is just the minimal changes to get asyncio tests working at all. I will take note of this comment for my other branch, but I think I've already got most of it covered there.
* bump pytest and pytest-asyncio to latest versions * regenerate lockfiles * remove unnecessary @pytest.mark.asyncio (we have asyncio_mode=auto) * fix endpoint provider unit test * equality operator for URI objects * update pants and ignore W503 which conflicts with black
* bump pytest and pytest-asyncio to latest versions * regenerate lockfiles * remove unnecessary @pytest.mark.asyncio (we have asyncio_mode=auto) * fix endpoint provider unit test * equality operator for URI objects * update pants and ignore W503 which conflicts with black
* bump pytest and pytest-asyncio to latest versions * regenerate lockfiles * remove unnecessary @pytest.mark.asyncio (we have asyncio_mode=auto) * fix endpoint provider unit test * equality operator for URI objects * update pants and ignore W503 which conflicts with black
* bump pytest and pytest-asyncio to latest versions * regenerate lockfiles * remove unnecessary @pytest.mark.asyncio (we have asyncio_mode=auto) * fix endpoint provider unit test * equality operator for URI objects * update pants and ignore W503 which conflicts with black
While running
./pants test ::on another branch, I noticed two related problems:async def test_*) aren't actually running even though they should because we have theasyncio_mode = "auto"setting inpyproject.toml.Simply upgrading pytest and pytest-asyncio to the latest minor versions resolves the issue. I tested this with the following dummy test file:
... and seeing two test failures and zero warnings.
Additionally, I removed the repo's one remaining but unnecessary
@pytest.mark.asyncio.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.