Comments (6)
Hi @fornellas, I have a question about this, in order to support asyncio, the whole module would have to drop python2 support right?
from testslide.
I suppose you're correct. Python 2 is dying anyway, it's support can be dropped at this point.
from testslide.
PS: I created a milestone for async stuff https://github.com/facebookincubator/TestSlide/milestone/1, as there's more stuff to implement.
from testslide.
@fried, what do you think about the approach of using inspect.iscoroutinefunction
to detect if the callable (module function, instance/class/static method) is async, and keep the self.mock_callable(
interface? The other option would be to have self.mock_async_callable(
. I understand that inspect has its limitations, I'm not experience with async to judge if this might lead to users shooting themselves in the foot in those cases.
from testslide.
I've put up #60 to provide mock_async_callable
. I do believe having an explicit mock_async_callable
is better than having the mock_callable
interface detect whether it's received a coroutine or a regular function. The latter just feels like it would hide too much from the users.
from testslide.
unittest.IsolatedAsyncioTestCase in 3.8 uses that. So to have async test methods they have to explicitly be coroutines. No sync methods that return awaitables, since that's pretty hairy.
Also the AsyncMock in 3.8 is also a really good interface for async mocks, in that it looks at the spec and if its a coroutine the mocks that return when that is called is another AsyncMock, otherwise you get a normal MagicMock.
from testslide.
Related Issues (20)
- Add linter to ensure Copyright header on files
- BUG: Leaked task detection triggers for cancelled tasks HOT 2
- Context methods can't be async and are being quietly ignored
- StrictMock validations broken when used via inheritance.
- Improve Coroutine value error error message
- patch_attribute issue with Python 3.10 HOT 1
- Testslide runner not playing well with unittest.subtests HOT 1
- [RFC] [runner] Use Pattern.search() instead of Pattern.match() for "--filter-regex" behavior HOT 1
- Make Gitlab CI running tests/linting also for pull requests. HOT 2
- add assert_called_times(times:int) for callable mocks HOT 1
- `and_assert_not_called` shouldn't need any behaviour defined beforehand HOT 2
- Make to_return_values work for patch attribute HOT 1
- Cannot mock method with signature `def ...(...) -> Awaitable[...]` due to TypeCheckError
- Windows support HOT 1
- Cannot type check with `from __future__ import annotations`
- Can't mock a @property without calling it? HOT 5
- AttributeError for asyncio.coroutines.CoroWrapper in Python 3.11.0 HOT 1
- Test failures with Pygments 2.14
- Request: Container Matchers HOT 3
- Test failures with python 3.11+
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testslide.