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

Pytest Coverage TPI #24156

Closed
3 tasks done
eleanorjboyd opened this issue Sep 23, 2024 · 0 comments
Closed
3 tasks done

Pytest Coverage TPI #24156

eleanorjboyd opened this issue Sep 23, 2024 · 0 comments
Labels
testplan-item Test plan item/assignments for upcoming release

Comments

@eleanorjboyd
Copy link
Member

eleanorjboyd commented Sep 23, 2024

Refs: #22827

Complexity: 5

Author: @eleanorjboyd

Create Issue


In this TPI you will be testing the new coverage implementation for Python!

Find or create a python project that has tests and test coverage. Hopefully copilot can help you with this but you can also look at my testing example repo and specifically this test which will call my inc_dec.py file with functions: https://github.com/eleanorjboyd/inc_dec_example_repo/blob/main/inc_dec_example_test_suite/test_unit_and_pytest_combo.py. Additionally the vscode-python extension can run with coverage too (for some specific ones, they error and I am looking into it, I think the specifics of running tests which run tests while running coverage might be causing interference between the actual test cases and the reporting)

  1. Create a venv using the "create environment command" choose python >= 3.8
  2. In the terminal, run python -m pip install pytest pytest-cov.
  3. From the command palette, run "python: configure tests", select pytest and then "." (root directory)
  4. click the test explorer icon (beaker)
  5. run tests with coverage using the button
  6. look at coverage by clicking the beaker icon below the test explorer icon
  7. create a function that has an "if / else" block, create tests so only one of those conditionals is met, make sure the UI shows the conditional you missed as not covered which will also appear red in the editor for that function.
  8. try different things and make sure they react correctly, ideas like: comments (shouldn't count towards coverage), blank lines (shouldn't count), blank files (shouldn't count and coverage should be grey in the coverage tab)
  9. in your settings.json you should see a "python.testing.pytestArgs": [], update this to include ["-cov=."] now make sure branch coverage is NOT included.
  10. update args to now be ["-cov=.", "--cov-report", "json"] make sure an json coverage report file is produced
@eleanorjboyd eleanorjboyd added the feature-request Request for new features or functionality label Sep 23, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 23, 2024
@eleanorjboyd eleanorjboyd added testplan-item Test plan item/assignments for upcoming release and removed feature-request Request for new features or functionality triage-needed Needs assignment to the proper sub-team labels Sep 23, 2024
@karthiknadig karthiknadig added this to the September 2024 milestone Sep 23, 2024
@bpasero bpasero assigned bpasero, Tyriar and bhavyaus and unassigned bpasero Sep 24, 2024
@rzhao271 rzhao271 assigned rzhao271 and unassigned Tyriar Sep 24, 2024
@rzhao271 rzhao271 removed their assignment Sep 24, 2024
@bhavyaus bhavyaus removed their assignment Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testplan-item Test plan item/assignments for upcoming release
Projects
None yet
Development

No branches or pull requests

6 participants