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

Add support for copying references to use with nose #5

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

Conversation

gherceg
Copy link

@gherceg gherceg commented Nov 18, 2023

Thanks for making this convenient plugin! One of the projects I work on uses nose as its test framework, and the path format for selecting specific classes/tests to run is different from what exists in this plugin currently. Notably, nose is no longer maintained but pynose is a drop-in replacement that supports the same format (see the Selecting Tests on the homepage).

In summary, when targeting specific tests in nose, there are two path options:

  1. some.package.path:SomeClass.some_function
  2. some/package/path.py:SomeClass.some_function

I have a personal preference for option 1, but tried supporting both options to see if one was less invasive than the other. For both formats, I found that an additional separator had to be introduced, whether it was to separate the module from the attributes, or the attributes themselves.

Given this, I went with option 1. I liked the idea of refactoring _get_attribute_parts to _get_attributes which accepts a separator and returns a string, behaving similarly to _get_module. The alternative was to keep the logic for building the attributes string in _get_reference which also works, but felt a bit less elegant.

Tests

I added tests/nose.vader to ensure this behaves as expected for both copying references to modules as well as attributes within a module.

I also updated the tests/pytest.vader to include a test for attributes as well, as it seemed like this was missing from the existing test suite since tests/attribute.vader only covers dotted behavior. It may be out of scope of this PR, but rather than have a separate tests/attribute.vader file, I think it makes sense to have an attribute test for each copy format in the relevant test file.

I've been using this locally with no issues, but mainly rely on nose and import references. If you're happy with this solution, I can also update the readme to mention this format as well.

When targeting specific tests in nose, there are two path options:
1) some.package.path:SomeClass.some_function
2) some/package/path.py:SomeClass.some_function

This adds support for option 1. I found that for either option, an
additional separator needs to be introduced, whether it is used to
separate the module from the attributes, or the attributes themselves.
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.

1 participant