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

Prevent branch mode warnings in unstaged mode #183

Merged
merged 2 commits into from
Nov 5, 2024
Merged

Prevent branch mode warnings in unstaged mode #183

merged 2 commits into from
Nov 5, 2024

Conversation

stevelacey
Copy link
Contributor

@stevelacey stevelacey commented Oct 29, 2024

Feel free to suggest a different way to shake this, I went for the quickest way to avoid the extra init.

Fixes #182

Copy link
Owner

@anapaulagomes anapaulagomes left a comment

Choose a reason for hiding this comment

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

Hi @stevelacey! Thanks a lot for your contribution 🎉

It is funny that now that I see this part of the code, I realize that an if/else code has avoided this issue. But back then, I assumed that more modes would come in fast. It's too early for that. haha

I've left a comment for you. Could you please add a regression test to prevent this issue from happening again and add a line to our CHANGELOG? 🙏🏽

I appreciate your contribution.

@@ -53,8 +53,7 @@ def _get_affected_paths(config):
_write(config, [error])
config.args = []
raise ValueError(error)
else:
return mode.affected_tests()
return mode[0](*mode[1:]).affected_tests()
Copy link
Owner

@anapaulagomes anapaulagomes Oct 30, 2024

Choose a reason for hiding this comment

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

What about changing it to something more readable?

    modes = {
        "branch": {
            "class": Branch,
            "args": (test_file_convention, parent_branch)
        },
        "unstaged": {
            "class": Unstaged,
            "args": (test_file_convention)
        },
    }
    try:
        mode = modes[picked_mode]
    except KeyError:
        error = "Invalid mode. Options: `{}`.".format(", ".join(modes.keys()))
        _write(config, [error])
        config.args = []
        raise ValueError(error)
    return mode["class"](*mode["args"]).affected_tests()

It is more verbose, but it helps when reading the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also had a version briefly where I used partial to pass Branch its extra kwarg, if you'd prefer that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, maybe lets pass test_file_convention explicitly, and then pass all options as kwargs to all modes and it's up to the mode to make use of whichever things it supports?

@stevelacey stevelacey closed this Oct 30, 2024
@anapaulagomes
Copy link
Owner

Hi @stevelacey, you closed the PR. Is that alright?

@stevelacey
Copy link
Contributor Author

stevelacey commented Oct 30, 2024

Oh, that's funny, I wrote I already fixed: <link to this pr> in a private repo and it closed this when I merged it 😂

@stevelacey stevelacey reopened this Oct 30, 2024
@stevelacey
Copy link
Contributor Author

@anapaulagomes hows that look? LGTM? 🙏

@anapaulagomes
Copy link
Owner

Thank you @stevelacey! Almost there! I appreciate it if you could write a test and add a line to the CHANGELOG. :)

@stevelacey stevelacey changed the title Move mode init after mode selection Prevent branch mode warnings from firing in unstaged mode Nov 1, 2024
@stevelacey
Copy link
Contributor Author

@anapaulagomes done

@stevelacey stevelacey changed the title Prevent branch mode warnings from firing in unstaged mode Prevent branch mode warnings in unstaged mode Nov 1, 2024
Copy link
Owner

@anapaulagomes anapaulagomes left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your contribution, @stevelacey! 🎉

@anapaulagomes anapaulagomes merged commit 26097bb into anapaulagomes:dev Nov 5, 2024
1 check passed
@stevelacey
Copy link
Contributor Author

@anapaulagomes great, thanks 🙌 can you release 0.5.1 on PyPi? 🙏

@anapaulagomes
Copy link
Owner

It's on my to-do list. The current process is not working because some parts are deprecated, so I'll have to make some changes or do it manually (and my current machine is not ready for it). Bear with me :)

@anapaulagomes
Copy link
Owner

There you go @stevelacey https://pypi.org/project/pytest-picked/0.5.1/

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.

Branch mode user warning fires outside of branch mode
2 participants