{"html_url": "https://github.com/simonw/datasette/pull/1960#issuecomment-1353812913", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1960", "id": 1353812913, "node_id": "IC_kwDOBm6k_c5QsYux", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-12-15T22:48:54Z", "updated_at": "2022-12-15T22:48:54Z", "author_association": "OWNER", "body": "This is all very broken:\r\n```\r\n% pytest -x --pdb\r\n================================================================================== test session starts ==================================================================================\r\nplatform darwin -- Python 3.10.3, pytest-7.1.3, pluggy-1.0.0\r\nSQLite: 3.39.4\r\nrootdir: /Users/simon/Dropbox/Development/datasette, configfile: pytest.ini\r\nplugins: anyio-3.6.1, xdist-2.5.0, forked-1.4.0, asyncio-0.19.0, timeout-2.1.0, profiling-1.7.0\r\nasyncio: mode=strict\r\ncollected 1295 items \r\n\r\ntests/test_package.py .. [ 0%]\r\ntests/test_cli.py . [ 0%]\r\ntests/test_cli_serve_get.py .. [ 0%]\r\ntests/test_cli.py . [ 0%]\r\ntests/test_black.py . [ 0%]\r\ntests/test_api.py E\r\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\r\n\r\nfixturedef = , request = >\r\n\r\n @pytest.hookimpl(hookwrapper=True)\r\n def pytest_fixture_setup(\r\n fixturedef: FixtureDef, request: SubRequest\r\n ) -> Optional[object]:\r\n \"\"\"Adjust the event loop policy when an event loop is produced.\"\"\"\r\n if fixturedef.argname == \"event_loop\":\r\n outcome = yield\r\n> loop = outcome.get_result()\r\n\r\n/Users/simon/.local/share/virtualenvs/datasette-AWNrQs95/lib/python3.10/site-packages/pytest_asyncio/plugin.py:377: \r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\r\n/Users/simon/Dropbox/Development/datasette/tests/conftest.py:30: in event_loop\r\n return asyncio.get_event_loop()\r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\r\n\r\nself = \r\n\r\n def get_event_loop(self):\r\n \"\"\"Get the event loop for the current context.\r\n \r\n Returns an instance of EventLoop or raises an exception.\r\n \"\"\"\r\n if (self._local._loop is None and\r\n not self._local._set_called and\r\n threading.current_thread() is threading.main_thread()):\r\n self.set_event_loop(self.new_event_loop())\r\n \r\n if self._local._loop is None:\r\n> raise RuntimeError('There is no current event loop in thread %r.'\r\n % threading.current_thread().name)\r\nE RuntimeError: There is no current event loop in thread 'MainThread'.\r\n\r\n/Users/simon/.pyenv/versions/3.10.3/lib/python3.10/asyncio/events.py:656: RuntimeError\r\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\r\n\r\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB post_mortem (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\r\n> /Users/simon/.pyenv/versions/3.10.3/lib/python3.10/asyncio/events.py(656)get_event_loop()\r\n-> raise RuntimeError('There is no current event loop in thread %r.'\r\n(Pdb) q\r\n\r\n\r\n=================================================================================== warnings summary ====================================================================================\r\ntests/test_cli.py::test_inspect_cli_writes_to_file\r\ntests/test_cli.py::test_inspect_cli\r\n /Users/simon/Dropbox/Development/datasette/datasette/cli.py:163: DeprecationWarning: There is no current event loop\r\n loop = asyncio.get_event_loop()\r\n\r\ntests/test_cli_serve_get.py::test_serve_with_get_exit_code_for_error\r\ntests/test_cli_serve_get.py::test_serve_with_get\r\n /Users/simon/Dropbox/Development/datasette/datasette/cli.py:596: DeprecationWarning: There is no current event loop\r\n asyncio.get_event_loop().run_until_complete(ds.invoke_startup())\r\n\r\ntests/test_cli_serve_get.py::test_serve_with_get_exit_code_for_error\r\ntests/test_cli_serve_get.py::test_serve_with_get\r\n /Users/simon/Dropbox/Development/datasette/datasette/cli.py:599: DeprecationWarning: There is no current event loop\r\n asyncio.get_event_loop().run_until_complete(check_databases(ds))\r\n\r\ntests/test_api.py::test_homepage\r\n /Users/simon/Dropbox/Development/datasette/tests/conftest.py:30: DeprecationWarning: There is no current event loop\r\n return asyncio.get_event_loop()\r\n\r\n-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html\r\n================================================================================ short test summary info ================================================================================\r\nERROR tests/test_api.py::test_homepage - RuntimeError: There is no current event loop in thread 'MainThread'.\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! _pytest.outcomes.Exit: Quitting debugger !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n======================================================================== 7 passed, 7 warnings, 1 error in 19.15s ========================================================================\r\n(datasette) datasette % \r\n```\r\nThe problem looks to be caused by this:\r\n\r\nhttps://github.com/simonw/datasette/blob/87737aa1ace82fa7b54c60c41471ec9a661f5299/tests/conftest.py#L28-L30\r\n\r\nWhich I found necessary in order to have `async def` fixtures that could be shared on the `scope=\"session\"` basis.\r\n\r\nCan I work around this, or is `scope=\"session\"` for async fixtures incompatible with my test suite for some reason?\r\n\r\n", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1499150951, "label": "Port as many tests as possible to async def tests against ds_client"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/pull/1960#issuecomment-1353805839", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1960", "id": 1353805839, "node_id": "IC_kwDOBm6k_c5QsXAP", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-12-15T22:38:37Z", "updated_at": "2022-12-15T22:38:37Z", "author_association": "OWNER", "body": "I'm going to make `.status_code` work on `TestClient` response too, so I don't have to worry about using both `status` or `status_code` depending on which kind of object I am using.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1499150951, "label": "Port as many tests as possible to async def tests against ds_client"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/pull/1960#issuecomment-1353765125", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1960", "id": 1353765125, "node_id": "IC_kwDOBm6k_c5QsNEF", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-12-15T22:00:04Z", "updated_at": "2022-12-15T22:00:04Z", "author_association": "OWNER", "body": "I'm going to punt on that for the moment and continue to use `app_client` for tests that use that mechanism.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1499150951, "label": "Port as many tests as possible to async def tests against ds_client"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/pull/1960#issuecomment-1353763837", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1960", "id": 1353763837, "node_id": "IC_kwDOBm6k_c5QsMv9", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-12-15T21:59:05Z", "updated_at": "2022-12-15T21:59:05Z", "author_association": "OWNER", "body": "Here's an annoying error:\r\n```\r\n> response4 = await ds_client.post(\r\n \"/-/logout\",\r\n csrftoken_from=True,\r\n cookies={\"ds_actor\": ds_client.actor_cookie({\"id\": \"test\"})},\r\n )\r\n\r\ntests/test_auth.py:88: \r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\r\n\r\nself = , path = '/-/logout'\r\nkwargs = {'cookies': {'ds_actor': 'eyJhIjp7ImlkIjoidGVzdCJ9fQ.fuFCTJG5XE-RNnUM7dcnXx9sPvE'}, 'csrftoken_from': True}, client = \r\n\r\n async def post(self, path, **kwargs):\r\n await self.ds.invoke_startup()\r\n async with httpx.AsyncClient(app=self.app) as client:\r\n> return await client.post(self._fix(path), **kwargs)\r\nE TypeError: AsyncClient.post() got an unexpected keyword argument 'csrftoken_from'\r\n```\r\nI need an alternative to the `csrftoken_from` mechanism I built for `TestClient`:\r\n\r\nhttps://github.com/simonw/datasette/blob/0b68996cc511b3a801f0cd0157bd66332d75f46f/datasette/utils/testing.py#L77-L103", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1499150951, "label": "Port as many tests as possible to async def tests against ds_client"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/pull/1960#issuecomment-1353749401", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1960", "id": 1353749401, "node_id": "IC_kwDOBm6k_c5QsJOZ", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-12-15T21:47:27Z", "updated_at": "2022-12-15T21:47:27Z", "author_association": "OWNER", "body": "I'm using this new mark:\r\n```python\r\n@pytest.mark.ds_client\r\n```\r\nPurely so I can run all of the tests that I've refactored using:\r\n\r\n```\r\npytest -m ds_client\r\n```\r\nI'll likely remove this once the test refactoring project is complete.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1499150951, "label": "Port as many tests as possible to async def tests against ds_client"}, "performed_via_github_app": null}