Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 1.2.0

- `pytest-cpp` no longer supports Python 3.4.
- New `cpp_ignore_py_files` option that makes the plugin ignore `*.py` files even if they
would otherwise match the `cpp_files` option (defaults to `True`).

# 1.1.0

Expand Down
32 changes: 23 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,34 @@ Once installed, when py.test runs it will search and run tests
found in executable files, detecting if the suites are
Google or Boost tests automatically.

Configuration Options
~~~~~~~~~~~~~~~~~~~~~

**cpp_files**

You can configure which files are tested for suites by using the ``cpp_files``
ini configuration:
ini configuration option:

.. code-block:: ini

[pytest]
cpp_files=test_suite*
cpp_files = test_suite*

By default matches ``test_*`` and ``*_test`` executable files.

Additional arguments to the C++ tests can be provided with the
``cpp_arguments`` ini configuration.
**cpp_arguments**

*New in version 1.1*.

Arguments to the C++ tests can be provided with the
``cpp_arguments`` ini configuration option.

For example:

.. code-block:: ini

[pytest]
cpp_arguments=-v --log-dir=logs
cpp_arguments =-v --log-dir=logs

You can change this option directly in the command-line using
pytest's ``-o`` option:
Expand All @@ -74,12 +81,19 @@ pytest's ``-o`` option:

$ pytest -o cpp_arguments='-v --log-dir=logs'

**cpp_ignore_py_files**

*New in version 1.2*.

Requirements
============
This option defaults to ``True`` and configures the plugin to ignore ``*.py`` files that
would otherwise match the ``cpp_files`` option.

* Python 2.7+, Python 3.4+
* pytest
Set it to ``False`` if you have C++ executable files that end with the ``*.py`` extension.

.. code-block:: ini

[pytest]
cpp_ignore_py_files = False

Install
=======
Expand Down
28 changes: 18 additions & 10 deletions pytest_cpp/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ def pytest_collect_file(parent, path):
return

config = parent.config
masks = config.getini('cpp_files') or DEFAULT_MASKS

test_args = config.getini(_ARGUMENTS) or ()
masks = config.getini('cpp_files')
test_args = config.getini('cpp_arguments')
cpp_ignore_py_files = config.getini('cpp_ignore_py_files')

# don't attempt to check *.py files even if they were given as explicit arguments
if cpp_ignore_py_files and path.fnmatch('*.py'):
return
if not parent.session.isinitpath(path):
for pat in masks:
if path.fnmatch(pat):
Expand All @@ -39,13 +42,18 @@ def pytest_collect_file(parent, path):


def pytest_addoption(parser):
parser.addini("cpp_files", type="args",
default=DEFAULT_MASKS,
help="glob-style file patterns for C++ test module discovery")
parser.addini(_ARGUMENTS,
type='args',
default='',
help='Additional arguments for test executables')
parser.addini('cpp_files',
type='args',
default=DEFAULT_MASKS,
help="glob-style file patterns for C++ test module discovery")
parser.addini('cpp_arguments',
type='args',
default=(),
help='additional arguments for test executables')
parser.addini('cpp_ignore_py_files',
type='bool',
default=True,
help='ignore *.py files that otherwise match "cpp_files" patterns')


class CppFile(pytest.File):
Expand Down
16 changes: 10 additions & 6 deletions tests/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ else:
CCFLAGS = ''
LIBS = ['pthread']

env = Environment(
CPPPATH=os.environ.get('INCLUDE'),
CCFLAGS=CCFLAGS,
LIBPATH=os.environ.get('LIBPATH'),
LIBS=LIBS,
)
kwargs = {
'CPPPATH': os.environ.get('INCLUDE'),
'CCFLAGS': CCFLAGS,
'LIBPATH': os.environ.get('LIBPATH'),
'LIBS': LIBS,
}
if 'CXX' in os.environ:
kwargs['CXX'] = os.environ['CXX']

env = Environment(**kwargs)
genv = env.Clone(LIBS=['gtest'] + LIBS)

Export('env genv')
Expand Down
25 changes: 25 additions & 0 deletions tests/test_pytest_cpp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import pytest
import subprocess
from pytest_cpp import error
Expand Down Expand Up @@ -260,6 +261,30 @@ def test_cpp_files_option(testdir, exes):
])


# skip to avoid dealing with exes.get appending extension
@pytest.mark.skipif(sys.platform.startswith('win'), reason='This is not a problem on Windows')
def test_cpp_ignore_py_files(testdir, exes):
file_name = 'cpptest_success.py'
exes.get('gtest', 'cpptest_success.py')
testdir.makeini('''
[pytest]
cpp_files = cpptest_*
''')

result = testdir.runpytest('--collect-only')
result.stdout.fnmatch_lines('* no tests ran *')

result = testdir.runpytest('--collect-only', '-o', 'cpp_ignore_py_files=False')
result.stdout.fnmatch_lines("*CppFile cpptest_success.py*")

# running directly skips out machinery as well.
result = testdir.runpytest('--collect-only', file_name)
result.stdout.fnmatch_lines('*1 error in*')

result = testdir.runpytest('--collect-only', '-o', 'cpp_ignore_py_files=False', file_name)
result.stdout.fnmatch_lines("*CppFile cpptest_success.py*")


def test_google_one_argument(testdir, exes):
testdir.makeini('''
[pytest]
Expand Down