Skip to content

Commit

Permalink
fix: reapproach api testing using markers
Browse files Browse the repository at this point in the history
  • Loading branch information
AlishChhetri committed Nov 21, 2023
1 parent 5cd91ae commit 4855df7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ developer-test-command = "pytest -x -s -m 'not fuzz'"
developer-test-silent-command = "pytest -x -m 'not fuzz' --show-capture=no"
hypothesis-test-command = "pytest -x -s -m 'fuzz'"
hypothesis-test-silent-command = "pytest -x -m 'fuzz' --show-capture=no"
not-openai-test = "pytest -x -s -m 'not api'"

[tool.taskipy.tasks]
all = "task black && task mypy && task ruff && task test"
Expand All @@ -104,13 +105,14 @@ developer-test = { cmd = "{developer-test-command}", help = "Run developer-creat
developer-test-silent = { cmd = "{developer-test-silent-command}", help = "Run developer-created without output", use_vars = true }
hypothesis = { cmd = "{hypothesis-test-command}", help = "Run the hypothesis-based test cases", use_vars = true}
hypothesis-silent = { cmd = "{hypothesis-test-silent-command}", help = "Run the hypothesis-based test cases", use_vars = true }
test = { cmd = "pytest -x -s -vv -n auto -k 'not test_createchecks'", help = "Run the pytest test suite using order randomization and test distribution excluding test_createchecks.py" }
test-not-randomly = { cmd = "pytest -x -s -vv -p no:randomly -k 'not test_createchecks'", help = "Run the pytest test suite without order randomization excluding test_createchecks.py" }
test-not-xdist = { cmd = "pytest -x -s -vv -p no:xdist -k 'not test_createchecks'", help = "Run the pytest test suite without order randomization excluding test_createchecks.py" }
test-silent = { cmd = "pytest -x --show-capture=no -n auto -k 'not test_createchecks'", help = "Run the pytest test suite without showing output excluding test_createchecks.py" }
test-silent-not-randomly = { cmd = "pytest -x --show-capture=no -p no:randomly -k 'not test_createchecks'", help = "Run the pytest test suite without showing output and order randomization excluding test_createchecks.py" }
test-silent-not-xdist = { cmd = "pytest -x --show-capture=no -p no:xdist -k 'not test_createchecks'", help = "Run the pytest test suite without showing output and test distribution excluding test_createchecks.py" }
test = { cmd = "pytest -x -s -vv -n auto", help = "Run the pytest test suite using order randomization and test distribution" }
test-not-randomly = { cmd = "pytest -x -s -vv -p no:randomly", help = "Run the pytest test suite without order randomization" }
test-not-xdist = { cmd = "pytest -x -s -vv -p no:xdist", help = "Run the pytest test suite without order randomization" }
test-silent = { cmd = "pytest -x --show-capture=no -n auto", help = "Run the pytest test suite without showing output" }
test-silent-not-randomly = { cmd = "pytest -x --show-capture=no -p no:randomly", help = "Run the pytest test suite without showing output and order randomization" }
test-silent-not-xdist = { cmd = "pytest -x --show-capture=no -p no:xdist", help = "Run the pytest test suite without showing output and test distribution" }
test-api = {cmd = "pytest -x -s -vv -n auto || pytest -x -s -vv -n auto", help = "Run the test_createchecks.py file only when provided with an API key", use_vars = true }
openai-test = { cmd = "{not-openai-test}", help = "Run openai powered test cases", use_vars = true }
test-coverage = { cmd = "{coverage-test-command}", help = "Run coverage monitoring for the test suite", use_vars = true }
test-coverage-silent = { cmd = "{coverage-test-command-silent}", help = "Run coverage monitoring for tests without output", use_vars = true }

Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[pytest]
markers =
api: test cases that use OpenAI API
fuzz: test cases that use Hypothesis for input generation
filterwarnings =
ignore::DeprecationWarning
3 changes: 3 additions & 0 deletions tests/test_createchecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def get_valid_api_key():
return os.getenv("API_KEY")


@pytest.mark.api
def test_valid_api_key():
"""Test is_valid_api_key function with a valid api key."""
valid_api_key = get_valid_api_key()
Expand All @@ -21,13 +22,15 @@ def test_valid_api_key():
assert result is True


@pytest.mark.api
def test_invalid_api_key():
"""Test is_valid_api_key function with an invalid api key."""
invalid_api_key = "fk-561sf56a1sf561as5f1asf165as1"
result = is_valid_api_key(invalid_api_key)
assert result is False


@pytest.mark.api
def test_generate_yaml_config():
valid_api_key = get_valid_api_key()
test_genscript = "Write: 'Hello, World'"
Expand Down

0 comments on commit 4855df7

Please sign in to comment.