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

fix: unit test execution in PyCharm (#1755) #1756

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

d10n
Copy link
Contributor

@d10n d10n commented Nov 19, 2024

  • Where does pathlib.Path('tests/data') resolve the path from? It's
    relative to the current working directory.
  • Where is the tests/data directory? Relative to the tests.
  • PyCharm has quirks related to the current working directory when
    running and debugging tests.
  • By using file to resolve the test data directory, we remove the
    non-guaranteed assumption that the current working directory is always
    at the root of the repository, and we replace that assumption with a
    value that is always correct regardless of current working directory.
  • As a result, the unit tests can now be debugged in PyCharm, unit tests
    can be executed from any directory, and test execution continues to
    work in all the places it originally worked.

Some of the handling is slightly messy but that can be cleaned up by
making the task config files themselves not dependent on the CWD

Types of changes

  • Hot fix (emergency fix and release)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation (change which affects the documentation site)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Release (develop -> main)

Quality assurance (all should be covered).

  • My code follows the code style of this project.
  • Documentation for my change is up to date?
  • My PR meets testing requirements.
  • All new and existing tests passed.
  • All commits are signed-off.

Summary

Key links:

Before you merge

  • Ensure it is a 'squash commit' if not a release.
  • Ensure CI is currently passing
  • Check sonar. If you are working for a fork a maintainer will reach out, if required.

d10n added 3 commits November 19, 2024 08:26
* Where does pathlib.Path('tests/data') resolve the path from? It's
  relative to the current working directory.
* Where is the tests/data directory? Relative to the tests.
* PyCharm has quirks related to the current working directory when
  running and debugging tests.
* By using __file__ to resolve the test data directory, we remove the
  non-guaranteed assumption that the current working directory is always
  at the root of the repository, and we replace that assumption with a
  value that is always correct regardless of current working directory.
* As a result, the unit tests can now be debugged in PyCharm, unit tests
  can be executed from any directory, and test execution continues to
  work in all the places it originally worked.

Some of the handling is slightly messy but that can be cleaned up by
making the task config files themselves not dependent on the CWD

Signed-off-by: d10n <[email protected]>
Signed-off-by: d10n <[email protected]>
@jpower432 jpower432 linked an issue Nov 21, 2024 that may be closed by this pull request
Copy link
Collaborator

@degenaro degenaro left a comment

Choose a reason for hiding this comment

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

Is there doc/tutorial on how one might take advantage of these changes by, for example, employing PyCharm to debug trestle?

For example in the contributing doc https://oscal-compass.github.io/compliance-trestle/contributing/mkdocs_contributing/ there is info on testing and such.

@d10n
Copy link
Contributor Author

d10n commented Dec 3, 2024

PyCharm has docs on creating the unit test configuration, but I'll add a short blurb about it to the docs here too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable running unit tests in PyCharm
2 participants