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

tasks: added --pytest-args to tests #100

Closed
wants to merge 1 commit into from

Conversation

mkmkme
Copy link
Collaborator

@mkmkme mkmkme commented Sep 24, 2024

Pull Request check-list

  • Do tests and lints pass with this change?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?

Description of change

Adds support for arbitrary pytest args for invoke tests/standalone_tests/cluster_tests

Fixes #62

Fixes #62

Signed-off-by: Mikhail Koviazin <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.17%. Comparing base (b060e38) to head (9d19ec0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #100      +/-   ##
==========================================
- Coverage   75.18%   75.17%   -0.01%     
==========================================
  Files         132      132              
  Lines       34480    34480              
==========================================
- Hits        25925    25922       -3     
- Misses       8555     8558       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -28,7 +28,9 @@ def build_docs(c):
def linters(c, color=False):
"""Run code linters"""
run(f"flake8 --color {'always' if color else 'never'} tests valkey")
run(f"black {'--color' if color else ''} --target-version py37 --check --diff tests valkey")
run(
Copy link
Member

Choose a reason for hiding this comment

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

Am I missing something or is this just a formatting change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah autoformatting changed this line for me :/ Do you want me to move it to a separate commit?

"""Run the valkey-py test suite against the current python,
with and without libvalkey.
"""
print("Starting Valkey tests")
print("pytest_args:", pytest_args)
Copy link
Member

Choose a reason for hiding this comment

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

By default this will print "pytest_args: None" which could be misleading as we pass a lot of arguments to pytest.
Maybe it would be better to explicitly say something like "user provided args"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is actually a leftover that I forgot to remove. Would you rather see it removed or having an additional proper message about pytest args?

"""Run tests against a valkey cluster"""
cluster_url = "valkey://localhost:16379/0"
color_arg = f"--color={'yes' if color else 'no'}"
shared_args = f"{color_arg} --protocol={protocol} --cov=./ --cov-report=xml:coverage_cluster.xml -W always -m 'not onlynoncluster and not valkeymod' --valkey-url={cluster_url}"
pytest_args = pytest_args or ""
Copy link
Member

Choose a reason for hiding this comment

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

Should we somehow try to validate pytest_args ?
As it is, it can be used to inject any kind of command (I don't mean just any arguments, you can use it to run any executable).
We, probably, shouldn't be too concerned about a malicious actor slipping some bad command in this argument, as it seems an unlikely scenario. But it may be possible for someone to inadvertently do something bad/wrong. Especially since complex argument passing will require a lot of escaping to be done correctly in this way.
I'm not sure if it's possible to sanitize this command in any reasonable way returning intelligible errors (most likely not). Maybe it would be better to handle the main pytest arguments as separate args here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can do this, yes. This approach leaves it to user's discretion. After all, any arguments they would pass they would run on their machine :)

Copy link
Member

Choose a reason for hiding this comment

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

What I mean is that this argument seem to be not easy to use, but it's easy to misuse.
Not easy to use: because you need to put your desired list of arguments in quotes but the most typical argument you may want to pass (i.e. -k) often needs quotes itself, so you need to use the right type of quotes or use escapes.
Easy to misuse: because I wouldn't expect a command like invoke tests --pytest-args="-k test ; rm -rf /" to wipe my HD. This is an extreme example, but still you may forgot some quotes here and there and run a completely different set of tests and get a green build when it should be red or the opposite.

@mkmkme mkmkme closed this by deleting the head repository Sep 30, 2024
@mkmkme
Copy link
Collaborator Author

mkmkme commented Oct 1, 2024

Closed in favor of #106

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.

allow for TESTARGS in invoke test
3 participants