Peculiar problem. I have a working codebase, inclu...
# general
a
Peculiar problem. I have a working codebase, including some tests that use pytest-asyncio. The codebase had a single resolve for all python deps. I am now breaking it into separate resolves. I have introduced a new resolve "edge" that includes a bunch of things, including the tests that use pytest-asyncio. locally I can run the tests. in CI, I receive an error
Copy code
async def functions are not natively supported.
You need to install a suitable plugin for your async framework, for example:
  - anyio
  - pytest-asyncio
  - pytest-tornasync
  - pytest-trio
  - pytest-twisted
Which implies that pytest-asyncio is not installed. pytest-asyncio is in the lockfile for both "edge" and the "pytest" resolve. I'm unsure where to go with this, or where to poke at it to try and reproduce.
f
What is in your
pants.toml
?
e
Copy code
[pytest]
install_from_resolve = "universal_resolve"
requirements = [
    "//3rdparty/python:poetry#pytest",
    "//3rdparty/python:poetry#pytest-asyncio",
]
I have this in my pants.toml. You might need something similar to enforce that pants knows to pick up the plugin dependency
e
pytest infers its plugins by searching your file system, so if you run in a sandbox as pants does, you need to explicitly set the dependency. In other words, pants can't tell that your tests need this plugin because there are no import statements or metadata in pytest itself that reference pytest-asyncio. So you have to be explicit about it
a
Sure.
Copy code
[pytest]
install_from_resolve = "pytest"
execution_slot_var = "PANTS_EXECUTION_SLOT"
args = [
  # This means we don't need to add the @pytest.mark.asyncio decorator above
  # async tests.
  "--asyncio-mode=auto",
]

# Include plugins and things that should be ambiently available here.
requirements = [
 "//3rdparty/python:pytest",
]
I'm a little confused by the interaction between pants.toml and pants.ci.toml here - from memory, the ci toml is merged with the base configuration, overriding things that are specified for ci?
Interestingly, if I remove the "asyncio-mode" from pants.toml, I get the same error locally, but adding it to ci.toml does not fix the problem on ci.
Copy code
❯ pants list 3rdparty/python:pytest
Does return 3rdparty/python:pytest#pytest-asyncio
and
3rdparty/python:test#time-machine@resolve=edge
though interestingly, nothing for
resolve=pytest
. 🤔
For anyone who wanders this way in future, I was missing the "--asyncio-mode=auto" in the pytest args of a different toml file, which was being used via PANTS_CONFIG_FILES in ci.