Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

Add template to extend pytest_addoption #176

Closed
wants to merge 1 commit into from

Conversation

yeganer
Copy link

@yeganer yeganer commented Jun 8, 2016

This template shows how to extend pytest_functions defined in
astropy.tests.pytest_plugins similiar to a super call in a class.

@yeganer
Copy link
Author

yeganer commented Jun 8, 2016

This is related to issue #175

@pllim
Copy link
Member

pllim commented Jun 8, 2016

Maybe extend the comments a little more to suggest how one might use the extra option?

This template shows how to extend pytest_functions defined in
astropy.tests.pytest_plugins similiar to a super call in a class.
@yeganer
Copy link
Author

yeganer commented Jun 13, 2016

@pllim I extended the comments. Do you want an example how the additional option could be used, too?
Somethink like this?

slow = pytest.mark.skipif(
    not pytest.config.getoption("--slow"),
    reason="need --slow option to run"
)

@pllim
Copy link
Member

pllim commented Jun 13, 2016

Thanks. I meant something more like "after you added this option, this is how you add the code in your test to use that option for your test..." This is because people who use the template have varying Python proficiency, so we should be as user-friendly as possible.

@yeganer
Copy link
Author

yeganer commented Jun 15, 2016

There are two ways one could show this.
The first is using the decorator I posted in the above comment.
The second one would be to create a fixture. This would have the benefit of showing the use of fixtures, too.
The fixture approach has the benefit that the solution is available in all tests where the @slow decorator needs to be implemented or imported in every file that uses it.

Which solution would you prefer to be in the example?

@pllim
Copy link
Member

pllim commented Jun 15, 2016

Ideally both, so user can choose. But if that is too much trouble, links to existing doc on how to accomplish them are sufficient.

@pllim
Copy link
Member

pllim commented Aug 15, 2016

I found a need for this and found out the following:

>>> import packagename
>>> packagename.test(slow=True)  # Error
>>> packagename.test(args='--slow')  # Okay

And also:

$ python setup.py test --slow  # Error
$ python setup.py test --args="--slow"  # Okay

This should be documented as well, along with the @slow decorator usage mentioned in http://doc.pytest.org/en/latest/example/simple.html.

pllim added a commit to pllim/stsynphot_refactor that referenced this pull request Aug 15, 2016
pllim added a commit to pllim/stsynphot_refactor that referenced this pull request Sep 2, 2016
pllim added a commit to pllim/stsynphot_refactor that referenced this pull request Sep 2, 2016
@bsipocz
Copy link
Member

bsipocz commented Apr 30, 2018

We're moving over to cookicutter, so I'm closing old unresolved PRs. Please reopen against the cookicutter branch if you feel this is still relevant.

@bsipocz bsipocz closed this Apr 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants