Skip to content

Instantly share code, notes, and snippets.

@roguh
Last active March 29, 2024 22:38
Show Gist options
  • Select an option

  • Save roguh/eae6f03861dc9fc5b737b69b334a1737 to your computer and use it in GitHub Desktop.

Select an option

Save roguh/eae6f03861dc9fc5b737b69b334a1737 to your computer and use it in GitHub Desktop.

Revisions

  1. roguh revised this gist Feb 22, 2024. 2 changed files with 6 additions and 2 deletions.
    6 changes: 5 additions & 1 deletion tox.ini
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # This demonstrates using tox to test different Python versions and different library versions on select Python versions.

    # TODO: use asdf, pyenv, Dockerfile to install many py versions

    # Dependencies: aiohttp
    # Dev dependencies: pytest pytest-asyncio pytest-cov tox tox-pyenv
    [tox]
    @@ -8,13 +10,14 @@ envlist =
    # 3.7 is EOL and 3.8 only has 1 more year of security updates
    # Test 3.8 with an old version of dependencies
    py38
    py38-oldaiohttp
    py39
    py39-oldaiohttp
    py310
    py311
    # The latest Python version.
    # Test it with an old version of dependencies
    py311-oldaiohttp
    py311-olderaiohttp
    # The future :)
    py312

    @@ -34,6 +37,7 @@ deps:
    # https://security.snyk.io/package/pip/aiohttp
    py39-oldaiohttp: aiohttp<3.9
    py311-oldaiohttp: aiohttp<3.9
    py311-olderaiohttp: aiohttp<3.8

    # Run unit tests with pytest.
    # Pytest can also run unit tests that only use the builtin unittest module.
    2 changes: 1 addition & 1 deletion tox_example.py
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    async def test_aiohttp_version():
    assert isinstance(aiohttp.__version__, str)
    if sys.version_info <= (3,8) or sys.version_info >= (3, 11):
    assert aiohttp.__version__ in ["3.9.3", "3.8.6"]
    assert aiohttp.__version__ in ["3.9.3", "3.8.6", "3.7.4.post0"]
    else:
    assert aiohttp.__version__ == "3.9.3" or aiohttp.__version__.startswith("4.")

  2. roguh revised this gist Feb 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tox.ini
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,8 @@ envlist =
    # 3.7 is EOL and 3.8 only has 1 more year of security updates
    # Test 3.8 with an old version of dependencies
    py38
    py38-oldaiohttp
    py39
    py39-oldaiohttp
    py310
    py311
    # The latest Python version.
  3. roguh revised this gist Feb 15, 2024. 2 changed files with 50 additions and 5 deletions.
    39 changes: 38 additions & 1 deletion tox.ini
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,40 @@
    # This demonstrates using tox to test different Python versions and different library versions on select Python versions.

    # Dependencies: aiohttp
    # Dev dependencies: pytest pytest-asyncio pytest-cov tox tox-pyenv
    [tox]
    envlist =
    py37,py38,py39
    # The oldest Python version we support
    # 3.7 is EOL and 3.8 only has 1 more year of security updates
    # Test 3.8 with an old version of dependencies
    py38
    py38-oldaiohttp
    py39
    py310
    py311
    # The latest Python version.
    # Test it with an old version of dependencies
    py311-oldaiohttp
    # The future :)
    py312

    [testenv]
    # Example here: https://stackoverflow.com/questions/57024579/tox-ini-environment-with-multiple-dependencies
    # 'deps' can also point to any number of requirements.txt or pyproject.toml files.
    # Here, we list all dependencies without using other files for the sake of simplicity.
    deps:
    # Install the latest version of aiohttp for all Python versions, with 2 exceptions.
    aiohttp
    tox-pyenv
    pytest
    pytest-asyncio
    pytest-cov
    # For the two Python versions where we'll support old libraries, install the old dependencies.
    # Old aiohttp versions have several CVEs, especially <=3.8.6
    # https://security.snyk.io/package/pip/aiohttp
    py39-oldaiohttp: aiohttp<3.9
    py311-oldaiohttp: aiohttp<3.9

    # Run unit tests with pytest.
    # Pytest can also run unit tests that only use the builtin unittest module.
    commands = pytest --cov-report term --cov-report html --cov=. --capture=no --durations=0 --durations-min=0.01 --log-cli-level=CRITICAL {posargs} tox_example.py
    16 changes: 12 additions & 4 deletions tox_example.py
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,18 @@
    import sys

    import aiohttp
    import pytest

    def test_aiohttp_version():
    assert isinstance(aiohttp.__version__, str)
    @pytest.mark.asyncio
    async def test_aiohttp_version():
    assert isinstance(aiohttp.__version__, str)
    if sys.version_info <= (3,8) or sys.version_info >= (3, 11):
    assert aiohttp.__version__ in ["3.9.3", "3.8.6"]
    else:
    assert aiohttp.__version__ == "3.9.3" or aiohttp.__version__.startswith("4.")

    def main():
    print("AIOHTTP version is", aiohttp.__version__)
    print("AIOHTTP version is", aiohttp.__version__)

    if __name__ == "__main__":
    main()
    main()
  4. roguh created this gist Feb 15, 2024.
    3 changes: 3 additions & 0 deletions tox.ini
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    [tox]
    envlist =
    py37,py38,py39
    10 changes: 10 additions & 0 deletions tox_example.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    import aiohttp

    def test_aiohttp_version():
    assert isinstance(aiohttp.__version__, str)

    def main():
    print("AIOHTTP version is", aiohttp.__version__)

    if __name__ == "__main__":
    main()