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

test: project scope fixtures for repo root and data dir #572

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aaraney
Copy link
Member

@aaraney aaraney commented Apr 5, 2024

This is a proof of concept solution to #570. For this to work, this will require running tests with pytest. In short, this exposes the repo root and data directory paths as pytest fixtures that can be utilized by pytest style tests and unittest.UnitTest tests. The unittest fixture variants set private properties on unittest.UnitTest instances.

Example of adding this functionality to a unittest.UnitTest:

import unittest
import pytest

@pytest.mark.usefixtures("repo_root_unittest")
class TestFoo(unittest.TestCase):
    def test_foo(self):
        # do something with repo root
        (self._repo_root / "LICENSE").read_text()

For those who have not been indoctrinated, here are a few links that will be helpful to understand pytests integration with unittest, the concept of a fixture, and fixture scopes.

edit: fixed link to the description / diagram of fixture scopes

@aaraney aaraney added the Under Consideration The feasibility and/or appropriateness of the issue are still being considered label Apr 5, 2024
@aaraney aaraney changed the title feat: project scope fixtures for repo root and data dir test: project scope fixtures for repo root and data dir Apr 5, 2024
@aaraney aaraney force-pushed the project_scope_pytest_fixtures branch from 5a53d47 to 7168ca2 Compare April 5, 2024 15:00
@aaraney
Copy link
Member Author

aaraney commented Apr 5, 2024

reworded the commit.

@christophertubbs
Copy link
Contributor

Any chance you can make a semi-bs/unnecessary fixture and refactor a low stakes unit test implementation to use it for a more concrete example? Or I guess add a new unit test that tests something super small as a rough example for those not in the know and don't know what 'read the manual' means?

@christophertubbs
Copy link
Contributor

I absolutely love it. I'd go ahead and merge it if the unit test didn't whine about not knowing what pytest was. Maybe that needs to work itself into the requirements.txt or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Under Consideration The feasibility and/or appropriateness of the issue are still being considered
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants