Skip to content

Commit

Permalink
Merge pull request #15 from pllim/pytest-8.1
Browse files Browse the repository at this point in the history
MNT: Compat with pytest>=8
  • Loading branch information
bsipocz authored Jan 9, 2024
2 parents 44747eb + f43b264 commit 0b7f50f
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 86 deletions.
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: ".github/workflows" # Location of package manifests
schedule:
interval: "weekly"
groups:
actions:
patterns:
- "*"
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
if: ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) || contains(github.event.pull_request.labels.*.name, 'Build wheels'))

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: 3.8

Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Run unit tests

on:
pull_request:
push:
branches: [ main ]
tags:
- '*'
workflow_dispatch:
schedule:
# Run every Thursday at 03:53 UTC
- cron: 53 3 * * 4

jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
python-version: 3.8
toxenv: py38-test-pytestoldest
- os: windows-latest
python-version: 3.8
toxenv: py38-test-pytest50
- os: macos-latest
python-version: 3.8
toxenv: py38-test-pytest51
- os: ubuntu-latest
python-version: 3.8
toxenv: py38-test-pytest52
- os: windows-latest
python-version: 3.8
toxenv: py38-test-pytest53
- os: ubuntu-latest
python-version: 3.8
toxenv: py38-test-pytest60
- os: ubuntu-latest
python-version: 3.9
toxenv: py39-test-pytest61
- os: ubuntu-latest
python-version: 3.9
toxenv: py39-test-pytest62
- os: ubuntu-latest
python-version: '3.10'
toxenv: py310-test-pytest70
- os: ubuntu-latest
python-version: '3.10'
toxenv: py310-test-pytest71
- os: windows-latest
python-version: '3.11'
toxenv: py311-test-pytest72
- os: ubuntu-latest
python-version: '3.11'
toxenv: py311-test-pytest73
- os: ubuntu-latest
python-version: '3.11'
toxenv: py311-test-pytest74
- os: ubuntu-latest
python-version: '3.12'
toxenv: py312-test-pytest80
- os: macos-latest
python-version: '3.12'
toxenv: py312-test-pytest80
- os: windows-latest
python-version: '3.12'
toxenv: py312-test-pytest80
- os: macos-latest
python-version: '3.11'
toxenv: py311-test-pytestdev
- os: windows-latest
python-version: '3.11'
toxenv: py311-test-pytestdev
- os: ubuntu-latest
python-version: '3.12'
toxenv: py312-test-pytestdev

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Tox
run: python -m pip install tox
- name: Run Tox
run: tox ${{ matrix.toxargs }} -v -e ${{ matrix.toxenv }}
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
0.1.3 (unreleased)
==================

- No changes yet.
- pytest 8.1 compatibility. [#15]

- Dropped Python 3.7 support. Minimum supported pytest is now 4.6. [#15]

0.1.2 (2022-12-11)
==================
Expand Down
34 changes: 0 additions & 34 deletions azure-pipelines.yml

This file was deleted.

135 changes: 98 additions & 37 deletions pytest_filter_subpackage/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
"""

import os

import pytest
from packaging.version import Version

_pytest_version = Version(pytest.__version__)
PYTEST_GE_8_0 = any([_pytest_version.is_devrelease,
_pytest_version.is_prerelease,
_pytest_version >= Version('8.0')])


def pytest_addoption(parser):
Expand All @@ -17,52 +24,106 @@ def pytest_addoption(parser):
"string to specify multiple packages.")


@pytest.hookimpl(tryfirst=True)
def pytest_ignore_collect(path, config):
if PYTEST_GE_8_0:

# NOTE: it is important that when we don't want to skip a file we return
# None and not False - if we return False pytest will not call any other
# pytest_ignore_collect function in other plugins, e.g. pytest-doctestplus.
@pytest.hookimpl(tryfirst=True)
def pytest_ignore_collect(collection_path, config):

# If the --package/-P option wasn't specified, don't do anything
if config.getvalue('package') is None:
return None
# NOTE: it is important that when we don't want to skip a file we return
# None and not False - if we return False pytest will not call any other
# pytest_ignore_collect function in other plugins, e.g. pytest-doctestplus.

# If the path is a directory, never skip - just do the filtering on a file
# by file basis.
if os.path.isdir(path):
return None
# If the --package/-P option wasn't specified, don't do anything
if config.getvalue('package') is None:
return None

# Otherwise ignore filename for remainder of checks
path = os.path.dirname(path)
# If the path is a directory, never skip - just do the filtering on a file
# by file basis.
if collection_path.is_dir():
return None

# Split path into components
path = path.split(os.path.sep)
# Otherwise ignore filename for remainder of checks
path = str(collection_path.parent)

# Split path into components
path = path.split(os.path.sep)

# Now cycle through and find the top level of the package - this is the
# last one that contains an ``__init__.py`` or ``index.rst`` file. We need
# to make sure that at least one of these files was found before escaping.
found_prev = False
for i in range(len(path), -1, -1):
subpath = os.path.sep.join(path[:i])
found = (os.path.exists(os.path.join(subpath, '__init__.py')) or
os.path.exists(os.path.join(subpath, 'index.rst')))
if found_prev and not found:
break
found_prev = found

# Now cycle through and find the top level of the package - this is the
# last one that contains an ``__init__.py`` or ``index.rst`` file. We need
# to make sure that at least one of these files was found before escaping.
found_prev = False
for i in range(len(path), -1, -1):
subpath = os.path.sep.join(path[:i])
found = (os.path.exists(os.path.join(subpath, '__init__.py')) or
os.path.exists(os.path.join(subpath, 'index.rst')))
if found_prev and not found:
break
found_prev = found
subpackage_path = path[i+1:]

subpackage_path = path[i+1:]
# Find selected sub-packages
selected = config.getvalue('package').strip().split(',')

# Find selected sub-packages
selected = config.getvalue('package').strip().split(',')
# Finally, we check if this is one of the specified ones
for subpackage_target in selected:
for i, target in enumerate(subpackage_target.split('.')):
if i >= len(subpackage_path) or target != subpackage_path[i]:
break

# Finally, we check if this is one of the specified ones
for subpackage_target in selected:
for i, target in enumerate(subpackage_target.split('.')):
if i >= len(subpackage_path) or target != subpackage_path[i]:
break
else:
return None

return True

else:

@pytest.hookimpl(tryfirst=True)
def pytest_ignore_collect(path, config):

else:
# NOTE: it is important that when we don't want to skip a file we return
# None and not False - if we return False pytest will not call any other
# pytest_ignore_collect function in other plugins, e.g. pytest-doctestplus.

# If the --package/-P option wasn't specified, don't do anything
if config.getvalue('package') is None:
return None

# If the path is a directory, never skip - just do the filtering on a file
# by file basis.
if os.path.isdir(path):
return None

return True
# Otherwise ignore filename for remainder of checks
path = os.path.dirname(path)

# Split path into components
path = path.split(os.path.sep)

# Now cycle through and find the top level of the package - this is the
# last one that contains an ``__init__.py`` or ``index.rst`` file. We need
# to make sure that at least one of these files was found before escaping.
found_prev = False
for i in range(len(path), -1, -1):
subpath = os.path.sep.join(path[:i])
found = (os.path.exists(os.path.join(subpath, '__init__.py')) or
os.path.exists(os.path.join(subpath, 'index.rst')))
if found_prev and not found:
break
found_prev = found

subpackage_path = path[i+1:]

# Find selected sub-packages
selected = config.getvalue('package').strip().split(',')

# Finally, we check if this is one of the specified ones
for subpackage_target in selected:
for i, target in enumerate(subpackage_target.split('.')):
if i >= len(subpackage_path) or target != subpackage_path[i]:
break

else:
return None

return True
13 changes: 8 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ url = https://github.com/astropy/pytest-filter-subpackage
author = The Astropy Developers
author_email = [email protected]
classifiers =
Development Status :: 3 - Alpha
Development Status :: 5 - Production/Stable
Framework :: Pytest
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Topic :: Software Development :: Testing
Topic :: Utilities
license = BSD
Expand All @@ -27,9 +27,9 @@ keywords = pytest, py.test
[options]
zip_safe = False
packages = find:
python_requires = >=3.7
python_requires = >=3.8
install_requires =
pytest>=3.0
pytest>=4.6

[options.entry_points]
pytest11 =
Expand All @@ -42,13 +42,16 @@ test =
pytest-cov

[tool:pytest]
minversion = 3.0
minversion = 4.6
testpaths = tests pytest_filter_subpackage
xfail_strict = true
filterwarnings =
error
ignore:file format.*:UserWarning
ignore:.*non-empty pattern match.*:FutureWarning

[flake8]
max-line-length = 100

[bdist_wheel]
universal = 1
Loading

0 comments on commit 0b7f50f

Please sign in to comment.