kwarunek / aiounittest Goto Github PK
View Code? Open in Web Editor NEWTest python asyncio-based code with ease.
Home Page: http://aiounittest.readthedocs.io
License: MIT License
Test python asyncio-based code with ease.
Home Page: http://aiounittest.readthedocs.io
License: MIT License
I am getting a test failure when built with pytest 8.2.1.
=================================== FAILURES ===================================
_______________ TestAsyncCaseWithCustomLoop.test_await_async_add _______________
../../BUILDROOT/python-aiounittest-1.3.1-16.fc41.x86_64/usr/lib/python3.12/site-packages/aiounittest/helpers.py:137: in wrapper
future = asyncio.ensure_future(ret, loop=loop)
/usr/lib64/python3.12/asyncio/tasks.py:695: in ensure_future
return loop.create_task(coro_or_future)
/usr/lib64/python3.12/asyncio/base_events.py:456: in create_task
self._check_closed()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_UnixSelectorEventLoop running=False closed=True debug=False>
def _check_closed(self):
if self._closed:
> raise RuntimeError('Event loop is closed')
E RuntimeError: Event loop is closed
/usr/lib64/python3.12/asyncio/base_events.py:541: RuntimeError
=============================== warnings summary ===============================
tests/test_asynctestcase_get_event_loop.py:30
/builddir/build/BUILD/aiounittest-1.3.1/tests/test_asynctestcase_get_event_loop.py:30: DeprecationWarning: There is no current event loop
self.my_loop = asyncio.get_event_loop()
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/test_asynctestcase_get_event_loop.py::TestAsyncCaseWithCustomLoop::test_await_async_add
============== 1 failed, 8 passed, 2 xfailed, 1 warning in 0.89s ===============
Hi,
Nose is deprecated since 2015, nobody should be using it anymore. Please switch to something more modern like pytest, and remove nose from your setup.py.
Right now mypy is not aware that aiounittest subclasses TestCase, which is a bummer for static typing. One has to
import aiounittest # type: ignore
which gives it the Any
type. Apart from disabling type checking, this also prevents us from turning on mypy --strict
mode which includes disallow_subclassing_any = True
or the following error ensues:
tests/test_case.py:15: error: Class cannot subclass 'AsyncTestCase' (has type 'Any')
It seems like we only need to add an empty py.typed
marker file as described in https://www.python.org/dev/peps/pep-0561/
When running multiple test cases using aiounittest under Python 3.8, the second and all the following unit test cases fail because there is no default event loop set in the MainThread. The following exception is raised when the unit tests are executed.
Traceback (most recent call last):
File "lib\site-packages\aiounittest\helpers.py", line 130, in wrapper
loop = get_brand_new_default_event_loop()
File "lib\site-packages\aiounittest\helpers.py", line 117, in get_brand_new_default_event_loop
old_loop = asyncio.get_event_loop()
File "lib\asyncio\events.py", line 639, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'MainThread'.
This exception occurs because get_brand_new_default_event_loop tries to get the default event loop after it has been closed in the decorator.
Looks like latest pytest shows some warnings
============================================================================= warnings summary =============================================================================
tests/test_asynctestcase.py:41
/home/tkloczko/rpmbuild/BUILD/aiounittest-1.4.1/tests/test_asynctestcase.py:41: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
def test_yield_async_add(self):
tests/test_asynctestcase.py:56
/home/tkloczko/rpmbuild/BUILD/aiounittest-1.4.1/tests/test_asynctestcase.py:56: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
def test_yield_async_add(self):
tests/test_asynctestcase_get_event_loop.py:38
/home/tkloczko/rpmbuild/BUILD/aiounittest-1.4.1/tests/test_asynctestcase_get_event_loop.py:38: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
def test_yield_async_add(self):
-- Docs: https://docs.pytest.org/en/stable/warnings.html
Can't call one test method directly:
$ python -m unittest my_test_module.MyTestCase.test_my_async_test
File ".../unittest/loader.py", line 205, in loadTestsFromName
test = obj()
TypeError: test_my_async_test() missing 1 required positional argument: 'self'
The reason is that the object given by __getattribute__
is tested against type.MethodType
,
but async_test(...)
is not.
Could not find a version that satisfies the requirement aiounitest (from versions: )
how to fix it? )
Hi :)
class Test(AsyncTestCase):
@patch('some_path.features_topic.send', new=AsyncMock())
async def test_smoke(self, mocked_topic):
...
I get a TypeError: test_smoke() missing 1 required positional argument: 'mocked_topic'
If I patch within the test with a with patch(..) as patched_object:
it works fine.
The PyPI version does not check if a test case method is a coroutine, only that it is a callable. This differs from what's in this repo, which I think is the more correct behavior:
def __getattribute__(self, name):
attr = super().__getattribute__(name)
if name.startswith('test_') and callable(attr):
return async_test(attr, loop=self.get_event_loop())
else:
return attr
The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.
The AsyncTestCase
assumes that only methods named test_*
can be async, which isn't necessarily a valid assumption. This restriction should be removed, since you already test if the given function is a coroutine.
RuntimeWarning: coroutine 'any_async_python_def' was never awaited
callable_obj(*args, **kwargs)
Hi there!
What about unittest.mock in asyncio?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.