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

Add template to extend pytest_addoption - #176

Closed
yeganer wants to merge 1 commit into
astropy:masterfrom
yeganer:master
Closed

yeganer wants to merge 1 commit into
astropy:masterfrom
yeganer:master

Conversation

@yeganer

@yeganer yeganer commented Jun 8, 2016

Copy link
Copy Markdown

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

@yeganer

yeganer commented Jun 8, 2016

Copy link
Copy Markdown
Author

This is related to issue #175

@pllim

pllim commented Jun 8, 2016

Copy link
Copy Markdown
Member

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

yeganer commented Jun 13, 2016

Copy link
Copy Markdown
Author

@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

pllim commented Jun 13, 2016

Copy link
Copy Markdown
Member

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

yeganer commented Jun 15, 2016

Copy link
Copy Markdown
Author

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

pllim commented Jun 15, 2016

Copy link
Copy Markdown
Member

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

pllim commented Aug 15, 2016 •

Copy link
Copy Markdown
Member

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

bsipocz commented Apr 30, 2018

Copy link
Copy Markdown
Member

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.

3 participants