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

Introduce fairseq2n pytest marker #83

Closed
wants to merge 1 commit into from
Closed

Introduce fairseq2n pytest marker #83

wants to merge 1 commit into from

Conversation

cbalioglu
Copy link
Contributor

Based on the discussion in #76, this PR introduces a pytest marker named fairseq2n to indicate which versions of fairseq2n are compatible with a marked test.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 4, 2023
Copy link
Contributor

@najielhachem najielhachem left a comment

Choose a reason for hiding this comment

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

LGTM

python_devel_only(),
reason="New fairseq2n API in Python-only installation. Skipping till v0.2.",
)
@pytest.mark.fairseq2n("0.2a0")
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to have a custom pytest marks?
why not using skip_if_fairseq2n_newer as an annotation ?

def skip_if_fairseq2n_newer(version):
  ...
  if ...:
     warnings.warn(...)
  return pytest.skip(installed_version < annotated_version, reason=f"The test requires fairseq2n v{annotated_version} or greater.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBH no particular reason. I just followed the instructions here: https://docs.pytest.org/en/7.1.x/example/markers.html. Looks like one advantage of using a pytest marker is that it integrates your marker with the pytest CLI (described here). It also makes it possible to use a marker in parametrized tests. Let me know if you have any objection on using a pytest marker though. I don't have a strong opinion on this.

def pytest_runtest_setup(item: pytest.Function) -> None:
marker = item.get_closest_marker(name="fairseq2n")
if marker is not None:
skip_if_fairseq2n_newer(*marker.args, **marker.kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

if we end up using custom marks can we have a link to documentation ? https://docs.pytest.org/en/stable/reference/reference.html#custom-marks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. I just realized that I should also update the contribution guidelines and mention this annotation there.

@cbalioglu
Copy link
Contributor Author

Not needed anymore after #124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants