Skip to content

Added plugin to filter by sub-packages #19

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
Empty file added pytest_astropy/__init__.py
Empty file.
Empty file.
46 changes: 46 additions & 0 deletions pytest_astropy/subpackage/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
This plugin provides support for specifying the -P option to test both
code and docs for a specific sub-package.
"""

import os


def pytest_addoption(parser):

parser.addoption("--package", "-P", action="store",
help="The name of a specific package to test, e.g. "
"'io.fits' or 'utils'. Accepts comma separated "
"string to specify multiple packages.")


def pytest_ignore_collect(path, config):

raise ValueError()

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

# Convert the path to the file being checked to a relative path.
path = os.path.relpath(path, os.path.curdir)

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

# We split the path up and ignore the first part of the path, which could
# be the main package name, or e.g. 'docs'.
split_path = path.split(os.path.sep)[1:]

# Now convert the remainder of the path to subpackage name
subpackage = '.'.join(split_path)

# Finally, we check if this is one of the specified ones
for subpackage_target in config.getvalue('package').split(','):
if subpackage.startswith(subpackage_target):
return False

return True
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def readme():
name='pytest-astropy',
version='0.6.0.dev',
license='BSD',
packages=find_packages(),
description='Meta-package containing dependencies for testing',
long_description=readme(),
author='The Astropy Developers',
Expand Down Expand Up @@ -56,5 +57,10 @@ def readme():
# Do not include as dependency until CI issues can be worked out
#'pytest-mpl',
'pytest-arraydiff>=0.1'
]
],
entry_points={
'pytest11': [
'pytest_astropy_subpackage = pytest_astropy.subpackage.plugin',
],
}
)