diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9179b31d..28b158af 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,9 +2,9 @@ version: 2 updates: - package-ecosystem: pip - directory: / + directory: /dependencies/default schedule: - interval: daily + interval: weekly open-pull-requests-limit: 10 target-branch: master - package-ecosystem: github-actions diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9036f312..70363f39 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 with: python-version: '3.10' - name: Install GitHub matcher for ActionLint checker @@ -42,7 +42,7 @@ jobs: id: version run: tox -e version-info - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: dist path: dist @@ -51,17 +51,17 @@ jobs: name: Python ${{ matrix.python-version }} runs-on: ubuntu-latest env: - USING_COVERAGE: 3.7,3.8,3.9,3.10 + USING_COVERAGE: 3.7,3.8,3.9,3.10,3.11 strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10'] + python-version: ['3.7', '3.8', '3.9', '3.10', 3.11-dev] steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Install dependencies @@ -107,7 +107,7 @@ jobs: with: fetch-depth: 0 - name: Download distributions - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: dist path: dist diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bf5f9e2c..8c15003b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: - markdown - rst - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt - rev: 0.1.0 + rev: 0.1.1 hooks: - id: yamlfmt args: [--mapping, '2', --sequence, '2', --offset, '0'] diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bb10c006..8de226c4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,12 @@ Changelog ========= +0.19.0 (22-07-13) +================= +- BREAKING: The default ``asyncio_mode`` is now *strict*. `#293 `_ +- Removes `setup.py` since all relevant configuration is present `setup.cfg`. Users requiring an editable installation of pytest-asyncio need to use pip v21.1 or newer. `#283 `_ +- Declare support for Python 3.11. + 0.18.3 (22-03-25) ================= - Adds `pytest-trio `_ to the test dependencies diff --git a/README.rst b/README.rst index 93b369b7..1fc5ef47 100644 --- a/README.rst +++ b/README.rst @@ -58,7 +58,7 @@ Modes ----- Starting from ``pytest-asyncio>=0.17``, three modes are provided: *auto*, *strict* and -*legacy* (default). +*legacy*. Starting from ``pytest-asyncio>=0.19`` the *strict* mode is the default. The mode can be set by ``asyncio_mode`` configuration option in `configuration file `_: @@ -104,6 +104,8 @@ pytest plugin can handle them. Please use this mode if multiple async frameworks should be combined in the same test suite. +This mode is used by default for the sake of project inter-compatibility. + Legacy mode ~~~~~~~~~~~ @@ -111,11 +113,10 @@ Legacy mode This mode follows rules used by ``pytest-asyncio<0.17``: tests are not auto-marked but fixtures are. -This mode is used by default for the sake of backward compatibility, deprecation -warnings are emitted with suggestion to either switching to ``auto`` mode or using -``strict`` mode with ``@pytest_asyncio.fixture`` decorators. +Deprecation warnings are emitted with suggestion to either switching to ``auto`` mode +or using ``strict`` mode with ``@pytest_asyncio.fixture`` decorators. -In future, the default will be changed. +The default was changed to ``strict`` in ``pytest-asyncio>=0.19``. Fixtures @@ -123,19 +124,16 @@ Fixtures ``event_loop`` ~~~~~~~~~~~~~~ -Creates and injects a new instance of the default asyncio event loop. By -default, the loop will be closed at the end of the test (i.e. the default -fixture scope is ``function``). +Creates a new asyncio event loop based on the current event loop policy. The new loop +is available as the return value of this fixture or via `asyncio.get_running_loop `__. +The event loop is closed when the fixture scope ends. The fixture scope defaults +to ``function`` scope. Note that just using the ``event_loop`` fixture won't make your test function a coroutine. You'll need to interact with the event loop directly, using methods like ``event_loop.run_until_complete``. See the ``pytest.mark.asyncio`` marker for treating test functions like coroutines. -Simply using this fixture will not set the generated event loop as the -default asyncio event loop, or change the asyncio event loop policy in any way. -Use ``pytest.mark.asyncio`` for this purpose. - .. code-block:: python def test_http_client(event_loop): @@ -143,22 +141,23 @@ Use ``pytest.mark.asyncio`` for this purpose. resp = event_loop.run_until_complete(http_client(url)) assert b"HTTP/1.1 200 OK" in resp -This fixture can be easily overridden in any of the standard pytest locations -(e.g. directly in the test file, or in ``conftest.py``) to use a non-default -event loop. This will take effect even if you're using the -``pytest.mark.asyncio`` marker and not the ``event_loop`` fixture directly. +The ``event_loop`` fixture can be overridden in any of the standard pytest locations, +e.g. directly in the test file, or in ``conftest.py``. This allows redefining the +fixture scope, for example: .. code-block:: python - @pytest.fixture + @pytest.fixture(scope="session") def event_loop(): - loop = MyCustomLoop() + policy = asyncio.get_event_loop_policy() + loop = policy.new_event_loop() yield loop loop.close() -If the ``pytest.mark.asyncio`` marker is applied, a pytest hook will -ensure the produced loop is set as the default global loop. -Fixtures depending on the ``event_loop`` fixture can expect the policy to be properly modified when they run. +If you need to change the type of the event loop, prefer setting a custom event loop policy over redefining the ``event_loop`` fixture. + +If the ``pytest.mark.asyncio`` marker is applied to a test function, the ``event_loop`` +fixture will be requested automatically by the test function. ``unused_tcp_port`` ~~~~~~~~~~~~~~~~~~~ @@ -251,7 +250,7 @@ Note about unittest ------------------- Test classes subclassing the standard `unittest `__ library are not supported, users -are recommended to use `unitest.IsolatedAsyncioTestCase `__ +are recommended to use `unittest.IsolatedAsyncioTestCase `__ or an async framework such as `asynctest `__. Contributing diff --git a/dependencies/default/constraints.txt b/dependencies/default/constraints.txt new file mode 100644 index 00000000..cd99339f --- /dev/null +++ b/dependencies/default/constraints.txt @@ -0,0 +1,24 @@ +async-generator==1.10 +attrs==21.4.0 +coverage==6.4.1 +flaky==3.7.0 +hypothesis==6.48.3 +idna==3.3 +importlib-metadata==4.12.0 +iniconfig==1.1.1 +mypy==0.961 +mypy-extensions==0.4.3 +outcome==1.2.0 +packaging==21.3 +pluggy==1.0.0 +py==1.11.0 +pyparsing==3.0.9 +pytest==7.1.2 +pytest-trio==0.7.0 +sniffio==1.2.0 +sortedcontainers==2.4.0 +tomli==2.0.1 +trio==0.21.0 +typed-ast==1.5.4 +typing_extensions==4.3.0 +zipp==3.8.0 diff --git a/dependencies/default/requirements.txt b/dependencies/default/requirements.txt new file mode 100644 index 00000000..01b2484e --- /dev/null +++ b/dependencies/default/requirements.txt @@ -0,0 +1,4 @@ +# Always adjust install_requires in setup.cfg and pytest-min-requirements.txt +# when changing runtime dependencies +pytest >= 6.1.0 +typing-extensions >= 3.7.2; python_version < "3.8" diff --git a/dependencies/pytest-min/constraints.txt b/dependencies/pytest-min/constraints.txt new file mode 100644 index 00000000..33f7948f --- /dev/null +++ b/dependencies/pytest-min/constraints.txt @@ -0,0 +1,22 @@ +async-generator==1.10 +attrs==21.4.0 +coverage==6.3.2 +flaky==3.7.0 +hypothesis==6.43.3 +idna==3.3 +iniconfig==1.1.1 +mypy==0.942 +mypy-extensions==0.4.3 +outcome==1.1.0 +packaging==21.3 +pluggy==0.13.1 +py==1.11.0 +pyparsing==3.0.8 +pytest==6.1.0 +pytest-trio==0.7.0 +sniffio==1.2.0 +sortedcontainers==2.4.0 +toml==0.10.2 +tomli==2.0.1 +trio==0.20.0 +typing_extensions==4.2.0 diff --git a/dependencies/pytest-min/requirements.txt b/dependencies/pytest-min/requirements.txt new file mode 100644 index 00000000..4fc6ef2f --- /dev/null +++ b/dependencies/pytest-min/requirements.txt @@ -0,0 +1,4 @@ +# Always adjust install_requires in setup.cfg and requirements.txt +# when changing minimum version dependencies +pytest == 6.1.0 +typing-extensions >= 3.7.2; python_version < "3.8" diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index 08001faf..dd6a782b 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -95,7 +95,7 @@ def pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager) -> None parser.addini( "asyncio_mode", help="default value for --asyncio-mode", - default="legacy", + default="strict", ) diff --git a/setup.cfg b/setup.cfg index 7b684e0f..b1f1e82d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,6 +22,7 @@ classifiers = Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 Topic :: Software Development :: Testing @@ -34,16 +35,17 @@ python_requires = >=3.7 packages = find: include_package_data = True +# Always adjust requirements.txt and pytest-min-requirements.txt when changing runtime dependencies install_requires = pytest >= 6.1.0 typing-extensions >= 3.7.2; python_version < "3.8" [options.extras_require] testing = - coverage==6.2 + coverage >= 6.2 hypothesis >= 5.7.1 flaky >= 3.5.0 - mypy == 0.931 + mypy >= 0.931 pytest-trio >= 0.7.0 [options.entry_points] diff --git a/setup.py b/setup.py deleted file mode 100644 index 7f1a1763..00000000 --- a/setup.py +++ /dev/null @@ -1,4 +0,0 @@ -from setuptools import setup - -if __name__ == "__main__": - setup() diff --git a/tox.ini b/tox.ini index 00d45222..1d8994ae 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 3.14.0 -envlist = py37, py38, py39, py310, lint, version-info, pytest-min +envlist = py37, py38, py39, py310, py311, lint, version-info, pytest-min isolated_build = true passenv = CI @@ -8,7 +8,8 @@ passenv = [testenv] extras = testing deps = - pytest == 6.2.5 # required for Python 3.10, not bad for others + --requirement dependencies/default/requirements.txt + --constraint dependencies/default/constraints.txt commands = make test allowlist_externals = make @@ -16,7 +17,8 @@ allowlist_externals = [testenv:pytest-min] extras = testing deps = - pytest == 6.1.0 + --requirement dependencies/pytest-min/requirements.txt + --constraint dependencies/pytest-min/constraints.txt commands = make test allowlist_externals = make @@ -50,4 +52,5 @@ python = 3.8: py38 3.9: py39 3.10: py310 + 3.11-dev: py311 pypy3: pypy3