Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings test #55

Merged
merged 9 commits into from
Jan 18, 2022
Merged

Add settings test #55

merged 9 commits into from
Jan 18, 2022

Conversation

machikoyasuda
Copy link
Member

@machikoyasuda machikoyasuda commented Jan 14, 2022

closes #54

What this PR does:

  • Adds 1 test to the test_settings file - this test should test that a new .env file with a different INPUT_HASH_ALGO variable will appropriately set that new value to settings.INPUT_HASH_ALGO.
  • Adds 1 new .env.settingstest file to be used on the new test, with the custom marker, @pytest.mark.settingstest
  • Adds 1 new pytest.ini file to register the new custom marker
  • Changes the run_test GitHub Action to run the test suite twice: on the first run, test all but the @pytest.mark.settingstest spec, and on the second run, run only that spec. In between the two runs, run source tests/.env.settingstest so that the test environment can read from the 2nd .env file
  • Refactors test_database and test_hash with parameterization

How I'm using the custom @pytest.mark

  1. Register the mark in pytest.ini - to document the mark and what it means. This isn't required for implementation, but is highly recommended:
[pytest]
markers =
    settingstest: mark a test to be run with .env.settingstest
  1. Use the custom mark in a method: @pytest.mark.settingstest:
@pytest.mark.settingstest
def test_hash_settings_env():
    assert settings.INPUT_HASH_ALGO == "sha512"
  1. Call pytest using the mark:
## Run all test with the mark
coverage run -m pytest -m settingstest
## Run all tests without the mark
coverage run -m pytest -m "not settingstest"

This is what the output looks like:

## Run all test with the mark
======================= 1 passed, 23 deselected in 0.10s =======================
## Run all tests without the mark
======================= 23 passed, 1 deselected in 2.09s =======================

@machikoyasuda machikoyasuda added this to the Courtesy Cards milestone Jan 14, 2022
@machikoyasuda machikoyasuda self-assigned this Jan 14, 2022
@machikoyasuda machikoyasuda marked this pull request as ready for review January 14, 2022 05:01
@machikoyasuda machikoyasuda changed the title Refactor/tests marks Add settings test Jan 14, 2022
Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm liking the parameterized tests!

.github/workflows/run-tests.yml Outdated Show resolved Hide resolved
Copy link
Member

@angela-tran angela-tran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameterization and the custom marks look good to me!

I agree with @thekaveman 's feedback that we could remove those redundant lines in the workflow.

Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Copy link
Member

@angela-tran angela-tran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@machikoyasuda machikoyasuda merged commit d22c091 into main Jan 18, 2022
@machikoyasuda machikoyasuda deleted the refactor/tests-marks branch January 18, 2022 21:14
@angela-tran angela-tran mentioned this pull request Nov 14, 2022
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Settings tests should test different environments / values
3 participants