Skip to content

Commit

Permalink
Sarracenia __init__ unit test (#730)
Browse files Browse the repository at this point in the history
* New sarracenia init tests

* Add pytest-mock requirement for unit tests

* Sarracenia init unit test

This has about 90% coverage

* Update tests README with extra info on config

Debugging tests wasn't working, and it's because generating code coverage while debugging breaks debugging.

* Add try/except around init tests that use xattr module

Apparently it's not a standard module everywhere, so this is a workaround
Could also juse use SR3's filemetadata methods, as they handle things "nicely"
  • Loading branch information
gcglinton committed Jul 26, 2023
1 parent b375512 commit e401ab3
Show file tree
Hide file tree
Showing 3 changed files with 548 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ If you want to run this in VSCode, and have it do all the things nicely, you'll
- [GitLens — Git supercharged](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens)
Not strictly required, but *very* strongly recommended as it makes VS Code's git features fully functional

Beyond that, changing a few options in your settings file will make it all work; thusly:
Beyond that, changing a few things in your VS Code configs will make it all work.

In `settings.json`, to get all the reports and coverage when running tests, and allow you to run individual tests even if they have dependencies:
```json
{
"python.testing.pytestArgs": [
"tests", "-v",
"--cov-config=tests/.coveragerc", "--cov=sarracenia", "--cov-report=xml", "--cov-report=html",
"--html=tests/report.html", "--self-contained-html",
"--failed-dependency-action=run", "--missing-dependency-action=run"
],
"python.testing.unittestEnabled": false,
Expand All @@ -69,6 +72,28 @@ Beyond that, changing a few options in your settings file will make it all work;
}
```


In `launch.json` (per [documentation](https://code.visualstudio.com/docs/python/testing#_debug-tests)), to enable full debugging support in your tests:
```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false,
"env": {"PYTEST_ADDOPTS": "--no-cov"}
}
]
}
```

**NOTE:** Don't just squash whatever you have in `settings.json`, or `launch.json`, but use some common sense to merge what's above into your existing files.

## Docker
You can also run the exact same tests from within a Docker container if you want to avoid having to (re)-provision clean installs.

Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pytest-cov>=4.0
pytest-bug>=1.2
pytest-depends>=1.0
pytest-html>=3.2
pytest-mock>=3.11

python-redis-lock>=4
fakeredis>=2.11
Expand Down
Loading

0 comments on commit e401ab3

Please sign in to comment.