Skip to content

[tests] add Python 3.10 env, update pytest dependency #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ jobs:
checks:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- python-version: 3.8
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-10.15]
python-version: [3.7, 3.8, 3.9]
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
Expand All @@ -20,11 +21,6 @@ jobs:
- name: Install tox
run: pip install tox

- name: Install playwright & browsers
run: |
pip install playwright
python -m playwright install

- name: Run tests
run: tox -e py

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
url="https://github.com/scrapy-plugins/scrapy-playwright",
packages=["scrapy_playwright"],
classifiers=[
"Development Status :: 1 - Planning",
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Framework :: Scrapy",
"Intended Audience :: Developers",
"Topic :: Internet :: WWW/HTTP",
Expand Down
46 changes: 46 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
Taken from
https://github.com/pytest-dev/pytest-asyncio/blob/25cf2b399e00a82b69951474eed074ba26cd0c3b/pytest_asyncio/plugin.py

Modify pytest_pycollect_makeitem to make use of the Function API
in pytest>=5.4.0 (pytest.Function.from_parent).

In the context of scrapy-playwright, this allows to unpin the outdated pytest<5.4.0 dependency,
while keeping pytest-asyncio==0.10, as pytest-asyncio>=0.11 currently breaks tests
(likely to be because of https://github.com/pytest-dev/pytest-asyncio/issues/157).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the problem pytest-dev/pytest-asyncio#157 or the fix for it (pytest-dev/pytest-asyncio#156) introduced in 0.12? Is pytest-asyncio>=0.12 not an option?

Copy link
Member Author

@elacuesta elacuesta Oct 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.11 is the first version that fails. I tried versions 0.12 and 0.15.1 (the latest at the time of writing) and they also fail. I think upgrading it might take some more research.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon closer inspection, the errors with 0.12 point to Twisted (RuntimeError: twisted reactor has stopped). There are probably some unexpected interactions with pytest-twisted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since pytest-dev/pytest-asyncio#157 is probably not the issue then, shall we just remove the parenthesized statement from the comment and merge?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, now the issues are mentioned here for future reference anyway 👍

"""


import asyncio
import inspect

import pytest

try:
from _pytest.python import transfer_markers
except ImportError: # Pytest 4.1.0 removes the transfer_marker api (#104)

def transfer_markers(*args, **kwargs): # noqa
"""Noop when over pytest 4.1.0"""
pass


def _is_coroutine(obj):
"""Check to see if an object is really an asyncio coroutine."""
return asyncio.iscoroutinefunction(obj) or inspect.isgeneratorfunction(obj)


@pytest.mark.tryfirst
def pytest_pycollect_makeitem(collector, name, obj):
"""A pytest hook to collect asyncio coroutines."""
if collector.funcnamefilter(name) and _is_coroutine(obj):
item = pytest.Function.from_parent(collector, name=name)

# Due to how pytest test collection works, module-level pytestmarks
# are applied after the collection step. Since this is the collection
# step, we look ourselves.
transfer_markers(obj, item.cls, item.module)
item = pytest.Function.from_parent(collector, name=name) # To reload keywords.

if "asyncio" in item.keywords:
return list(collector._genfunctions(name, obj))
9 changes: 5 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ envlist = bandit,black,flake8,typing,py
deps =
playwright>=1.8.0a1
scrapy>=2.0,!=2.4.0
pytest<5.4
pytest-asyncio<0.11
pytest-cov>=2.8
pytest-twisted>=1.11
pytest==6.2.5
pytest-asyncio==0.10
pytest-cov==3.0.0
pytest-twisted==1.13.4
commands =
playwright install
py.test --reactor=asyncio \
--cov-report=term-missing --cov-report=html --cov-report=xml \
--cov=scrapy_playwright {posargs: scrapy_playwright tests}
Expand Down