Skip to content

Latest commit

 

History

History
220 lines (146 loc) · 7.13 KB

CONTRIBUTING.rst

File metadata and controls

220 lines (146 loc) · 7.13 KB

Contribution getting started

Contributions are highly welcomed and appreciated. Every little help counts, so do not hesitate!

Feature requests and feedback

Do you like pytest? Share some love on Twitter or in your blog posts!

We'd also like to hear about your propositions and suggestions. Feel free to submit them as issues and:

  • Explain in detail how they should work.
  • Keep the scope as narrow as possible. This will make it easier to implement.

Report bugs

Report bugs this plugin in the issue tracker.

If you are reporting a bug, please include:

  • Your operating system name and version.
  • Any details about your local setup that might be helpful in troubleshooting, specifically the Python interpreter version, installed libraries, and pytest version.
  • Detailed steps to reproduce the bug.

If you can write a demonstration test that currently fails but should pass (xfail), that is a very useful commit to make as well, even if you cannot fix the bug itself.

Fix bugs

Look through the GitHub issues for bugs.

:ref:`Talk <contact>` to developers to find out how you can fix specific bugs.

Don't forget to check the issue trackers of your favourite plugins, too!

Implement features

Look through the GitHub issues for enhancements.

:ref:`Talk <contact>` to developers to find out how you can implement specific features.

Write documentation

Pytest could always use more documentation. What exactly is needed?

  • More complementary documentation. Have you perhaps found something unclear?
  • Documentation translations. We currently have only English.
  • Docstrings. There can never be too many of them.
  • Blog posts, articles and such -- they're all very appreciated.

You can also edit documentation files directly in the GitHub web interface, without using a local copy. This can be convenient for small fixes.

Preparing Pull Requests

Short version

  1. Fork the repository.

  2. Target master for bugfixes and doc changes.

  3. Target features for new features or functionality changes.

  4. Follow PEP-8 for naming and black for formatting.

  5. Tests are run using tox:

    tox -e py37
    

    The test environments above are usually enough to cover most cases locally.

Long version

What is a "pull request"? It informs the project's core developers about the changes you want to review and merge. Pull requests are stored on GitHub servers. Once you send a pull request, we can discuss its potential modifications and even add more commits to it later on. There's an excellent tutorial on how Pull Requests work in the GitHub Help Center.

Here is a simple overview, with pytest-specific bits:

  1. Fork the pytest-nunit GitHub repository. It's fine to use pytest-nunit as your fork repository name because it will live under your user.

  2. Clone your fork locally using git and create a branch:

    $ git clone git@github.com:YOUR_GITHUB_USERNAME/pytest-nunit.git
    $ cd pytest-nunit
    # now, to fix a bug create your own branch off "master":
    
        $ git checkout -b your-bugfix-branch-name master
    
    # or to instead add a feature create your own branch off "features":
    
        $ git checkout -b your-feature-branch-name features
    

    Given we have "major.minor.micro" version numbers, bugfixes will usually be released in micro releases whereas features will be released in minor releases and incompatible changes in major releases.

    If you need some help with Git, follow this quick start guide: https://git.wiki.kernel.org/index.php/QuickStart

  3. Install tox

    Tox is used to run all the tests and will automatically setup virtualenvs to run the tests in. (will implicitly use http://www.virtualenv.org/en/latest/):

    $ pip install tox
    
  4. Run all the tests

    You need to have Python 3.7 available in your system. Now running tests is as simple as issuing this command:

    $ tox -e py37
    

    This command will run tests via the "tox" tool against Python 3.7.

  5. You can now edit your local working copy and run the tests again as necessary. Please follow PEP-8 for naming.

    You can pass different options to tox. For example, to run tests on Python 3.7 and pass options to pytest (e.g. enter pdb on failure) to pytest you can do:

    $ tox -e py37 -- --pdb
    
  6. Commit and push once your tests pass and you are happy with your change(s):

    $ git commit -a -m "<commit message>"
    $ git push -u
    
  7. Create a new changelog entry in changelog. The file should be named <issueid>.<type>.rst, where issueid is the number of the issue related to the change and type is one of bugfix, removal, feature, vendor, doc or trivial. You may not create a changelog entry if the change doesn't affect the documented behaviour of Pytest.

  8. Finally, submit a pull request through the GitHub website using this data:

    head-fork: YOUR_GITHUB_USERNAME/pytest-nunit
    compare: your-branch-name
    
    base-fork: pytest-dev/pytest-nunit
    base: master          # if it's a bugfix
    base: features        # if it's a feature
    

Writing Tests

Writing tests for plugins or for pytest itself is often done using the testdir fixture, as a "black-box" test.

For example, to ensure a simple test passes you can write:

def test_true_assertion(testdir):
    testdir.makepyfile(
        """
        def test_foo():
            assert True
    """
    )
    result = testdir.runpytest()
    result.assert_outcomes(failed=0, passed=1)

Alternatively, it is possible to make checks based on the actual output of the termal using glob-like expressions:

def test_true_assertion(testdir):
    testdir.makepyfile(
        """
        def test_foo():
            assert False
    """
    )
    result = testdir.runpytest()
    result.stdout.fnmatch_lines(["*assert False*", "*1 failed*"])

When choosing a file where to write a new test, take a look at the existing files and see if there's one file which looks like a good fit. For example, a regression test about a bug in the --lf option should go into test_cacheprovider.py, given that this option is implemented in cacheprovider.py. If in doubt, go ahead and open a PR with your best guess and we can discuss this over the code.