Working with tests: locally and in CI

Running tests locally with PyCharm

To configure tests locally you need to perform several steps:

  1. Install tests dependencies:

    python -m pip install -r requirements_qa.txt
    

Important

Ensure you have activated your environment if you have such by running .\venv\Scripts\activate (Windows) or source venv\bin\activate (macOS).

  1. Create a new configuration:

    ../../_images/pycharm_create_configuration2.jpg
  2. Choose pytest as a target:

    ../../_images/pycharm_choose_pytest_template2.jpg
  3. Fill pytest configuration and click OK:

    ../../_images/pycharm_fill_pytest_configuration2.jpg
  4. Run pytest configuration:

    ../../_images/pycharm_run_pytest2.jpg

    This should run all the tests in the repository. You can inspect them by clicking through a list at the bottom of a screen.

    ../../_images/pycharm_tests_report2.png
  5. As you have some tests failing, you want to debug them. Then, first, you need to limit a scope of running tests and the mark level you want to get for an assignment. For example, you might want to run checks for a crawler configuration. Then you need to return to configuration menu and pass additional parameters, like -m stage_2_1_crawler_config_check.

    ../../_images/pycharm_control_tests_scope2.jpg

    You can choose any of the labels that are described in ../pyproject.toml and combine with a mark. For example, running the aforementioned check for configuration for a mark 8 will look like -m "mark8 and stage_2_1_crawler_config_check".

Hint

To running all tests for first assignment for mark 8: -m "mark8 and (stage_2_1_crawler_config_check or stage_2_2_crawler_check or stage_2_3_HTML_parser_check or stage_2_4_dataset_volume_check or stage_2_5_dataset_validation)"

Hint

When you want to debug a test, instead of running them, put a breakpoint at the potentially vulnerable place of code and execute debugging by clicking a ‘bug’ button.

Running tests in command-line

  1. Install dependencies (assuming you have activated the environment from the previous step):

    python -m pip install -r requirements_qa.txt
    
  2. Run the tests for the given mark. You can select any level: mark4, mark6, mark8, mark10:

    python -m pytest -m mark8
    

Running tests in CI

Tests will never run until you create a Pull Request.

The very first check happens exactly when you create a pull request. After that, each time you push changes in your fork, CI check will be automatically started, normally within a minute or two. To see the results, navigate to your PR and click either the particular step in the report at the end of a page, or click Checks in the toolbar.

../../_images/ci_report2.png ../../_images/ci_tab2.png

Inspect each step by clicking through the list to the left.