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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Trio testing with Hypothesis #44

Merged
merged 1 commit into from
Jun 29, 2018

Conversation

Zac-HD
Copy link
Member

@Zac-HD Zac-HD commented Jun 27, 2018

Closes #42, based on my work upstream in HypothesisWorks/hypothesis#1343.

CC @njsmith and @zmitchell - note that you'll need a recent version of Hypothesis as the mechanism to support this was literally released yesterday! It's public API and perfectly stable though, agreeing on a design we liked enough to support long-term is the main thing that took us so long 馃槃

@codecov
Copy link

codecov bot commented Jun 27, 2018

Codecov Report

Merging #44 into master will decrease coverage by 0.41%.
The diff coverage is 95.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #44      +/-   ##
==========================================
- Coverage    95.7%   95.28%   -0.42%     
==========================================
  Files          10       11       +1     
  Lines         256      276      +20     
  Branches       23       26       +3     
==========================================
+ Hits          245      263      +18     
- Misses          8        9       +1     
- Partials        3        4       +1
Impacted Files Coverage 螖
pytest_trio/_tests/test_hypothesis_interaction.py 100% <100%> (酶)
pytest_trio/plugin.py 90.9% <90.9%> (-1.01%) 猬囷笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 8a52d49...ccd5ec2. Read the comment docs.

@given(st.integers())
@pytest.mark.trio
async def test_mark_inner(n):
pass
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be interesting to add a isinstance(n, int) check in the body just to be sure ?

@given(x=st.integers())
@pytest.mark.trio
async def test_mark_and_parametrize(x, y):
pass
Copy link
Member

Choose a reason for hiding this comment

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

Same here, but I would make the parametrize and given produce different types of data just to be sure we don't get x and y mixed

print(dir(item.obj))
if hasattr(item.obj, 'hypothesis'):
# If it's a Hypothesis test, we go in a layer. We *don't* check
# that this is a coroutine function, because we might have wrapped
Copy link
Member

Choose a reason for hiding this comment

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

I'm concerned about the "might have wrapped", what happened if the test function is synchronous but wrapper in a hypothesis.given ? I would say we must always check the test function is async (because we will always call it async still and get a crash if it's not the case).

A simple solution I see is to move the check within _trio_test_runner_factory (given it is currently called just after the check it would change nothing, and it's pretty evident the parameter passed to this factory must be an async function)

@@ -1,2 +1,3 @@
pytest
pytest-cov
hypothesis
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we add a >=3.64.0 rule to this requirement ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! You should probably add minimum versions to pytest and pytest-cov too then, as I'm sure there are some old enough that they don't work...

@touilleMan
Copy link
Member

Thanks for the PR, I'm really eager to merge this one 馃槂

@touilleMan touilleMan merged commit b6cf633 into python-trio:master Jun 29, 2018
@touilleMan
Copy link
Member

馃挴 Great 馃 job 馃帀 @Zac-HD 馃嵕 !

@njsmith
Copy link
Member

njsmith commented Jun 29, 2018

Thanks, and welcome! 馃帀 馃巶 No pressure, but if you'd like to keep contributing then we'd love to have you, so I'm sending you a github invite now. You can read more about this in our contributing documentation.

@Zac-HD
Copy link
Member Author

Zac-HD commented Jun 29, 2018

I'm delighted to be on the team, and will certainly hang around! Also delighted by the contributing docs - they're excellent, congrats 馃帀

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.

None yet

3 participants