<commit_before>pytest-console-scripts
===================================

.. image:: https://travis-ci.org/kvas-it/pytest-console-scripts.svg?branch=master
    :target: https://travis-ci.org/kvas-it/pytest-console-scripts
    :alt: See Build Status on Travis CI

Pytest-console-scripts is a `Pytest`_ plugin for testing python scripts
installed via ``console_scripts`` entry point of ``setup.py``. It can run the
scripts under test in a separate process or using the interpreter that's
running the test suite.  The former mode ensures that the script will run in an
environment that is identical to normal execution whereas the latter one allows
much quicker test runs during development while simulating the real runs as
much as possible.


Requirements
------------

* Python 2.7 or 3.4+, or PyPy,
* Pytest 3.0 or newer.


Installation
------------

You can install "pytest-console-scripts" via `pip`_ from `PyPI`_::

    $ pip install pytest-console-scripts


Usage
-----

Imagine we have a python package ``foo`` with the following ``setup.py``:

.. code-block:: python

    setup(
        name='foo',
        version='0.0.1',
        py_modules=['foo'],
        entry_points={
            'console_scripts': ['foobar=foo:bar']
        },
    )

We could use pytest-console-scripts to test the ``foo`` script:

.. code-block:: python

    def test_foo_bar(script_runner):
        ret = script_runner.run('foo', 'bar')
        assert ret.success
        assert ret.stdout == 'bar\n'
        assert ret.stderr == ''

This would use the ``script_runner`` fixture provided by the plugin to
run the script and capture it's output.

The arguments of ``script_runner.run`` are the command name of the script and
any command line arguments that should be passed to it. Additionally the
following keyword arguments can be used:

- ``cwd`` - set the working directory of the script under test.
- ``stdin`` - a file-like object that will be piped to standard input of the
  script.

Configuring script execution mode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In the example above the ``foobar`` script would run in in-process mode. This
is fast and good for quick iteration during development. After we're happy with<commit_msg>fix script name + more meaningful option example<commit_after>pytest-console-scripts
===================================

.. image:: https://travis-ci.org/kvas-it/pytest-console-scripts.svg?branch=master
    :target: https://travis-ci.org/kvas-it/pytest-console-scripts
    :alt: See Build Status on Travis CI

Pytest-console-scripts is a `Pytest`_ plugin for testing python scripts
installed via ``console_scripts`` entry point of ``setup.py``. It can run the
scripts under test in a separate process or using the interpreter that's
running the test suite.  The former mode ensures that the script will run in an
environment that is identical to normal execution whereas the latter one allows
much quicker test runs during development while simulating the real runs as
much as possible.


Requirements
------------

* Python 2.7 or 3.4+, or PyPy,
* Pytest 3.0 or newer.


Installation
------------

You can install "pytest-console-scripts" via `pip`_ from `PyPI`_::

    $ pip install pytest-console-scripts


Usage
-----

Imagine we have a python package ``foo`` with the following ``setup.py``:

.. code-block:: python

    setup(
        name='foo',
        version='0.0.1',
        py_modules=['foo'],
        entry_points={
            'console_scripts': ['foobar=foo:bar']
        },
    )

We could use pytest-console-scripts to test the ``foobar`` script:

.. code-block:: python

    def test_foo_bar(script_runner):
        ret = script_runner.run('foobar', '--version')
        assert ret.success
        # just for example, let's assume that foobar --version 
        # should output 3.2.1
        assert ret.stdout == '3.2.1\n'
        assert ret.stderr == ''

This would use the ``script_runner`` fixture provided by the plugin to
run the script and capture it's output.

The arguments of ``script_runner.run`` are the command name of the script and
any command line arguments that should be passed to it. Additionally the
following keyword arguments can be used:

- ``cwd`` - set the working directory of the script under test.
- ``stdin`` - a file-like object that will be piped to standard input of the
  script.

Configuring script execution mode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In the example above the ``foobar`` script would run in in-process mode. This
is fast and good for quick iteration during development. After we're happy with
{'fraction_non_alphanumeric': 0.12967417450251476, 'fraction_numerical': 0.005248195932648152, 'mean_word_length': 3.3479087452471483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1908223', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1253, 'n_words': 526}