flake8-aaa


Nameflake8-aaa JSON
Version 0.17.0 PyPI version JSON
download
home_pagehttps://github.com/jamescooke/flake8-aaa
SummaryA Flake8 plugin that checks Python tests follow the Arrange-Act-Assert pattern
upload_time2023-10-30 16:53:16
maintainer
docs_urlNone
authorJames Cooke
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Flake8-AAA
==========

.. image:: https://img.shields.io/github/actions/workflow/status/jamescooke/flake8-aaa/build.yml?branch=master
    :alt: GitHub Workflow Status
    :target: https://github.com/jamescooke/flake8-aaa/actions?query=branch%3Amaster

.. image:: https://img.shields.io/readthedocs/flake8-aaa.svg
    :alt: Read the Docs
    :target: https://flake8-aaa.readthedocs.io/

.. image:: https://img.shields.io/pypi/v/flake8-aaa.svg
    :alt: PyPI
    :target: https://pypi.org/project/flake8-aaa/

.. image:: https://img.shields.io/pypi/dm/flake8-aaa
    :alt: PyPI monthly downloads
    :target: https://pypistats.org/packages/flake8-aaa

.. image:: https://img.shields.io/pypi/pyversions/flake8-aaa.svg
    :alt: PyPI - Python Version
    :target: https://pypi.org/project/flake8-aaa/

.. image:: https://img.shields.io/github/license/jamescooke/flake8-aaa.svg
    :alt: flake8-aaa is licensed under the MIT License
    :target: https://github.com/jamescooke/flake8-aaa/blob/master/LICENSE

..

A Flake8 plugin that checks Python tests follow the Arrange-Act-Assert pattern.

----------

📝 Table of Contents
--------------------

* `About <#-about>`_
* `Getting Started <#-getting-started>`_
* `Usage <#-usage>`_
* `Compatibility <#-compatibility>`_
* `Resources <#-resources>`_

🧐 About
--------

What is the Arrange-Act-Assert pattern?
.......................................

"Arrange-Act-Assert" is a testing pattern that focuses each test on a single
object's behaviour. It's also known as "AAA" and "3A".

As the name suggests each test is broken down into three distinct parts
separated by blank lines:

* **Arrange:** Set up the object to be tested.

* **Act**: Carry out an action on the object.

* **Assert**: Check the expected results have occurred.

For example, a simple test on the behaviour of add ``+``:

.. code-block:: python

    def test() -> None:
       x = 1
       y = 1

       result = x + y

       assert result == 2

As you can see, the Act block starts with ``result =`` and is separated from
the Arrange and Assert blocks by blank lines. The test is focused - it only
contains one add operation and no further additions occur.

Using AAA consistently makes it easier to find the Action in a test. It's
therefore always easy to see the object behaviour each test is focused on.

Further reading:

* `Arrange-Act-Assert: A Pattern for Writing Good Tests
  <https://automationpanda.com/2020/07/07/arrange-act-assert-a-pattern-for-writing-good-tests/>`_
  - a great introduction to AAA from a Python perspective.

* `Anatomy of a test
  <https://docs.pytest.org/en/latest/explanation/anatomy.html>`_ - a
  description of Arrange Act Assert in the Pytest documentation.

* `Arrange Act Assert pattern for Python developers
  <https://jamescooke.info/arrange-act-assert-pattern-for-python-developers.html>`_
  - information about the pattern and each part of a test.

* `Our "good" example files
  <https://github.com/jamescooke/flake8-aaa/tree/master/examples/good>`_ -
  test examples used in the Flake8-AAA test suite.

What is Flake8?
...............

Flake8 is a command line utility for enforcing style consistency across Python
projects. It wraps multiple style checking tools and also runs third-party
checks provided by plugins, of which Flake8-AAA is one.

Further reading:

* `Flake8's documentation <https://flake8.pycqa.org/en/latest/>`_.

* `Awesome Flake8 Extensions
  <https://github.com/DmytroLitvinov/awesome-flake8-extensions/>`_ - a curated
  list of Flake8 plugins.

What does Flake8-AAA do?
........................

Flake8-AAA extends Flake8 to check your Python tests match the AAA pattern.

It does this by adding the following checks to Flake8:

* Every test has a single clear Act block.

* Every Act block is distinguished from the code around it with a blank line
  above and below.

* Arrange and Assert blocks do not contain additional blank lines.

In the future, Flake8-AAA will check that no test has become too complicated
and that Arrange blocks do not contain assertions.

Checking your code with these simple formatting rules helps you write simple,
consistently formatted tests that match the AAA pattern. They are most helpful
if you call Flake8 regularly, for example when you save a file or before you
run a test suite.

Further reading:

* `Error codes documentation
  <https://flake8-aaa.readthedocs.io/en/stable/error_codes/all.html>`_: A list
  of error codes raised by Flake8-AAA when a test doesn't match the AAA
  pattern.

🏁 Getting Started
------------------

Installation
............

Install ``flake8-aaa``:

.. code-block:: shell

    pip install flake8-aaa

This will install Flake8-AAA and its dependencies, which include Flake8.

You can confirm that Flake8 recognises the plugin by checking its version
string:

.. code-block:: shell

    flake8 --version

.. code-block::

    6.1.0 (flake8-aaa: 0.17.0, mccabe: 0.7.0, pycodestyle: 2.11.1, pyflakes: 3.1.0) CPython 3.11.6 on Linux

The ``flake8-aaa: 0.17.0`` part tells you that Flake8-AAA was installed
successfully and its checks will be used by Flake8.

Further reading:

* `Flake8 installation instructions
  <https://flake8.pycqa.org/en/latest/index.html#installation-guide>`_.

First run
.........

Let's check the good example from above. We expect Flake8 to return no errors:

.. code-block:: shell

    curl https://raw.githubusercontent.com/jamescooke/flake8-aaa/master/examples/good/test_example.py > test_example.py
    flake8 test_example.py

Silence - just what we wanted.

Now let's see a failure from Flake8-AAA. We can use a bad example:

.. code-block:: shell

    curl https://raw.githubusercontent.com/jamescooke/flake8-aaa/master/examples/bad/test.py > test.py
    flake8 test.py

.. code-block::

    test.py:4:1: AAA01 no Act block found in test

🎈 Usage
--------

Since Flake8-AAA is a Flake8 plugin, the majority of its usage is
dependent on how you use Flake8. In general you can point it at your source
code and test suite:

.. code-block:: shell

    flake8 src tests

If you're not already using Flake8 then you might consider:

* Adding a hook to your code editor to run Flake8 when you save a file.

* Adding a pre-commit hook to your source code manager to run Flake8 before you
  commit.

* Running Flake8 before you execute your test suite - locally or in CI.

If you just want Flake8-AAA error messages you can filter errors returned by
Flake8 with ``--select``:

.. code-block:: shell

    flake8 --select AAA tests

Further reading:

* `Flake8-AAA options and configuration
  <https://flake8-aaa.readthedocs.io/en/stable/options.html>`_.

* `Using Flake8 <https://flake8.pycqa.org/en/stable/user/index.html>`_.

⛏️ Compatibility
----------------

Flake8-AAA works with:

* Pytest and unittest test suites.

* Black and yapf formatted code.

* Mypy and type-annotated code.

* Active versions of Python 3 as listed on the `python.org downloads page
  <https://www.python.org/downloads/>`_.

Further reading:

* `Full compatibility list
  <https://flake8-aaa.readthedocs.io/en/stable/compatibility.html>`_ - includes
  how to configure Flake8-AAA to work with Black and information on support for
  older versions of Python.

📕 Resources
------------

* `Documentation on ReadTheDocs <https://flake8-aaa.readthedocs.io/>`_

* `Package on PyPI <https://pypi.org/project/flake8-aaa/>`_

* `Source code on GitHub <https://github.com/jamescooke/flake8-aaa>`_

* `Licensed on MIT <https://github.com/jamescooke/flake8-aaa/blob/master/LICENSE>`_

* `Changelog <https://github.com/jamescooke/flake8-aaa/blob/master/CHANGELOG.rst>`_

* `#flake8_aaa hashtag on Mastodon <https://fosstodon.org/tags/flake8_aaa>`_

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jamescooke/flake8-aaa",
    "name": "flake8-aaa",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "James Cooke",
    "author_email": "github@jamescooke.info",
    "download_url": "https://files.pythonhosted.org/packages/ed/70/488869c58c09bffd95eca7e3cc9b30988595105fb63057f9111975b2d9a1/flake8-aaa-0.17.0.tar.gz",
    "platform": null,
    "description": "Flake8-AAA\n==========\n\n.. image:: https://img.shields.io/github/actions/workflow/status/jamescooke/flake8-aaa/build.yml?branch=master\n    :alt: GitHub Workflow Status\n    :target: https://github.com/jamescooke/flake8-aaa/actions?query=branch%3Amaster\n\n.. image:: https://img.shields.io/readthedocs/flake8-aaa.svg\n    :alt: Read the Docs\n    :target: https://flake8-aaa.readthedocs.io/\n\n.. image:: https://img.shields.io/pypi/v/flake8-aaa.svg\n    :alt: PyPI\n    :target: https://pypi.org/project/flake8-aaa/\n\n.. image:: https://img.shields.io/pypi/dm/flake8-aaa\n    :alt: PyPI monthly downloads\n    :target: https://pypistats.org/packages/flake8-aaa\n\n.. image:: https://img.shields.io/pypi/pyversions/flake8-aaa.svg\n    :alt: PyPI - Python Version\n    :target: https://pypi.org/project/flake8-aaa/\n\n.. image:: https://img.shields.io/github/license/jamescooke/flake8-aaa.svg\n    :alt: flake8-aaa is licensed under the MIT License\n    :target: https://github.com/jamescooke/flake8-aaa/blob/master/LICENSE\n\n..\n\nA Flake8 plugin that checks Python tests follow the Arrange-Act-Assert pattern.\n\n----------\n\n\ud83d\udcdd Table of Contents\n--------------------\n\n* `About <#-about>`_\n* `Getting Started <#-getting-started>`_\n* `Usage <#-usage>`_\n* `Compatibility <#-compatibility>`_\n* `Resources <#-resources>`_\n\n\ud83e\uddd0 About\n--------\n\nWhat is the Arrange-Act-Assert pattern?\n.......................................\n\n\"Arrange-Act-Assert\" is a testing pattern that focuses each test on a single\nobject's behaviour. It's also known as \"AAA\" and \"3A\".\n\nAs the name suggests each test is broken down into three distinct parts\nseparated by blank lines:\n\n* **Arrange:** Set up the object to be tested.\n\n* **Act**: Carry out an action on the object.\n\n* **Assert**: Check the expected results have occurred.\n\nFor example, a simple test on the behaviour of add ``+``:\n\n.. code-block:: python\n\n    def test() -> None:\n       x = 1\n       y = 1\n\n       result = x + y\n\n       assert result == 2\n\nAs you can see, the Act block starts with ``result =`` and is separated from\nthe Arrange and Assert blocks by blank lines. The test is focused - it only\ncontains one add operation and no further additions occur.\n\nUsing AAA consistently makes it easier to find the Action in a test. It's\ntherefore always easy to see the object behaviour each test is focused on.\n\nFurther reading:\n\n* `Arrange-Act-Assert: A Pattern for Writing Good Tests\n  <https://automationpanda.com/2020/07/07/arrange-act-assert-a-pattern-for-writing-good-tests/>`_\n  - a great introduction to AAA from a Python perspective.\n\n* `Anatomy of a test\n  <https://docs.pytest.org/en/latest/explanation/anatomy.html>`_ - a\n  description of Arrange Act Assert in the Pytest documentation.\n\n* `Arrange Act Assert pattern for Python developers\n  <https://jamescooke.info/arrange-act-assert-pattern-for-python-developers.html>`_\n  - information about the pattern and each part of a test.\n\n* `Our \"good\" example files\n  <https://github.com/jamescooke/flake8-aaa/tree/master/examples/good>`_ -\n  test examples used in the Flake8-AAA test suite.\n\nWhat is Flake8?\n...............\n\nFlake8 is a command line utility for enforcing style consistency across Python\nprojects. It wraps multiple style checking tools and also runs third-party\nchecks provided by plugins, of which Flake8-AAA is one.\n\nFurther reading:\n\n* `Flake8's documentation <https://flake8.pycqa.org/en/latest/>`_.\n\n* `Awesome Flake8 Extensions\n  <https://github.com/DmytroLitvinov/awesome-flake8-extensions/>`_ - a curated\n  list of Flake8 plugins.\n\nWhat does Flake8-AAA do?\n........................\n\nFlake8-AAA extends Flake8 to check your Python tests match the AAA pattern.\n\nIt does this by adding the following checks to Flake8:\n\n* Every test has a single clear Act block.\n\n* Every Act block is distinguished from the code around it with a blank line\n  above and below.\n\n* Arrange and Assert blocks do not contain additional blank lines.\n\nIn the future, Flake8-AAA will check that no test has become too complicated\nand that Arrange blocks do not contain assertions.\n\nChecking your code with these simple formatting rules helps you write simple,\nconsistently formatted tests that match the AAA pattern. They are most helpful\nif you call Flake8 regularly, for example when you save a file or before you\nrun a test suite.\n\nFurther reading:\n\n* `Error codes documentation\n  <https://flake8-aaa.readthedocs.io/en/stable/error_codes/all.html>`_: A list\n  of error codes raised by Flake8-AAA when a test doesn't match the AAA\n  pattern.\n\n\ud83c\udfc1 Getting Started\n------------------\n\nInstallation\n............\n\nInstall ``flake8-aaa``:\n\n.. code-block:: shell\n\n    pip install flake8-aaa\n\nThis will install Flake8-AAA and its dependencies, which include Flake8.\n\nYou can confirm that Flake8 recognises the plugin by checking its version\nstring:\n\n.. code-block:: shell\n\n    flake8 --version\n\n.. code-block::\n\n    6.1.0 (flake8-aaa: 0.17.0, mccabe: 0.7.0, pycodestyle: 2.11.1, pyflakes: 3.1.0) CPython 3.11.6 on Linux\n\nThe ``flake8-aaa: 0.17.0`` part tells you that Flake8-AAA was installed\nsuccessfully and its checks will be used by Flake8.\n\nFurther reading:\n\n* `Flake8 installation instructions\n  <https://flake8.pycqa.org/en/latest/index.html#installation-guide>`_.\n\nFirst run\n.........\n\nLet's check the good example from above. We expect Flake8 to return no errors:\n\n.. code-block:: shell\n\n    curl https://raw.githubusercontent.com/jamescooke/flake8-aaa/master/examples/good/test_example.py > test_example.py\n    flake8 test_example.py\n\nSilence - just what we wanted.\n\nNow let's see a failure from Flake8-AAA. We can use a bad example:\n\n.. code-block:: shell\n\n    curl https://raw.githubusercontent.com/jamescooke/flake8-aaa/master/examples/bad/test.py > test.py\n    flake8 test.py\n\n.. code-block::\n\n    test.py:4:1: AAA01 no Act block found in test\n\n\ud83c\udf88 Usage\n--------\n\nSince Flake8-AAA is a Flake8 plugin, the majority of its usage is\ndependent on how you use Flake8. In general you can point it at your source\ncode and test suite:\n\n.. code-block:: shell\n\n    flake8 src tests\n\nIf you're not already using Flake8 then you might consider:\n\n* Adding a hook to your code editor to run Flake8 when you save a file.\n\n* Adding a pre-commit hook to your source code manager to run Flake8 before you\n  commit.\n\n* Running Flake8 before you execute your test suite - locally or in CI.\n\nIf you just want Flake8-AAA error messages you can filter errors returned by\nFlake8 with ``--select``:\n\n.. code-block:: shell\n\n    flake8 --select AAA tests\n\nFurther reading:\n\n* `Flake8-AAA options and configuration\n  <https://flake8-aaa.readthedocs.io/en/stable/options.html>`_.\n\n* `Using Flake8 <https://flake8.pycqa.org/en/stable/user/index.html>`_.\n\n\u26cf\ufe0f Compatibility\n----------------\n\nFlake8-AAA works with:\n\n* Pytest and unittest test suites.\n\n* Black and yapf formatted code.\n\n* Mypy and type-annotated code.\n\n* Active versions of Python 3 as listed on the `python.org downloads page\n  <https://www.python.org/downloads/>`_.\n\nFurther reading:\n\n* `Full compatibility list\n  <https://flake8-aaa.readthedocs.io/en/stable/compatibility.html>`_ - includes\n  how to configure Flake8-AAA to work with Black and information on support for\n  older versions of Python.\n\n\ud83d\udcd5 Resources\n------------\n\n* `Documentation on ReadTheDocs <https://flake8-aaa.readthedocs.io/>`_\n\n* `Package on PyPI <https://pypi.org/project/flake8-aaa/>`_\n\n* `Source code on GitHub <https://github.com/jamescooke/flake8-aaa>`_\n\n* `Licensed on MIT <https://github.com/jamescooke/flake8-aaa/blob/master/LICENSE>`_\n\n* `Changelog <https://github.com/jamescooke/flake8-aaa/blob/master/CHANGELOG.rst>`_\n\n* `#flake8_aaa hashtag on Mastodon <https://fosstodon.org/tags/flake8_aaa>`_\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Flake8 plugin that checks Python tests follow the Arrange-Act-Assert pattern",
    "version": "0.17.0",
    "project_urls": {
        "Homepage": "https://github.com/jamescooke/flake8-aaa"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e8f082e3a6604959ac05a82e425784887af1aa200471d9e688ce8d54bd167000",
                "md5": "144aa1a137081443d3438c582db8d64a",
                "sha256": "c9212d1fb94d1a95433c2ae18a644f96c33ee6ac059644d116e4dade0f191988"
            },
            "downloads": -1,
            "filename": "flake8_aaa-0.17.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "144aa1a137081443d3438c582db8d64a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 20599,
            "upload_time": "2023-10-30T16:53:14",
            "upload_time_iso_8601": "2023-10-30T16:53:14.497449Z",
            "url": "https://files.pythonhosted.org/packages/e8/f0/82e3a6604959ac05a82e425784887af1aa200471d9e688ce8d54bd167000/flake8_aaa-0.17.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed70488869c58c09bffd95eca7e3cc9b30988595105fb63057f9111975b2d9a1",
                "md5": "274748569be329016ed7a7ea2825f2a4",
                "sha256": "97dccdffa8e603dcf9cd9b4c2012e6fa22d58a2264a8b51146dcc9b63be66803"
            },
            "downloads": -1,
            "filename": "flake8-aaa-0.17.0.tar.gz",
            "has_sig": false,
            "md5_digest": "274748569be329016ed7a7ea2825f2a4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 19989,
            "upload_time": "2023-10-30T16:53:16",
            "upload_time_iso_8601": "2023-10-30T16:53:16.731020Z",
            "url": "https://files.pythonhosted.org/packages/ed/70/488869c58c09bffd95eca7e3cc9b30988595105fb63057f9111975b2d9a1/flake8-aaa-0.17.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-30 16:53:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jamescooke",
    "github_project": "flake8-aaa",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "flake8-aaa"
}
        
Elapsed time: 0.25598s