Repository navigation
Fix for pytest.mark.enable_socket - #28
TripleDogDare wants to merge 1 commit into
Conversation
|
Not sure what's up with appveyor. Seems pretty unrelated. |
|
Thanks - I haven't had a chance to look at this, and will try to come back to evaluate this in a few weeks. |
| with pytest.raises(BaseException): | ||
| assert_socket_blocked(result) |
There was a problem hiding this comment.
It seems there's no need in assert_socket_blocked check. The with block can be deleted. The main check is result.assert_outcomes(1, 0, 0).
There was a problem hiding this comment.
It's consistent with the other tests this way though.
There was a problem hiding this comment.
Indeed, but it is strange. Look at the definition of it
def assert_socket_blocked(result):
result.stdout.fnmatch_lines("""
*SocketBlockedError: A test tried to use socket.socket.*
""")AFAICT, assert_socket_blocked() does not raise an exception ...
https://docs.pytest.org/en/latest/_modules/_pytest/pytester.html#Testdir.runpytest
which can return
https://docs.pytest.org/en/latest/reference.html#_pytest.pytester.RunResult
But when we use fnmatch on the line matcher, I guess that can throw due to pytest fail()?
https://docs.pytest.org/en/latest/reference.html#_pytest.pytester.LineMatcher.fnmatch_lines
Anyway the point is, let's make sure the logic is correct. The TLDR I think is that assert_socket_blocked(result) will throw an exception if socket IS NOT blocked.
So test_enable_socket_marker SHOULD NOT BLOCK the socket via @pytest.mark.enable_socket, so therefore assert_socket_blocked(result) SHOULD be raising an exception.
TBH this is a confusing way to do it, but as @TripleDogDare points out, this is the convention of all other tests. The "proper" thing to do IMO is write an assertion method called assert_socket_not_blocked() (but that is out of scope of this activity).
|
@TripleDogDare could you rebase onto master this PR? The issue with AppVeyor is fixed in #34. |
atugushev
left a comment
There was a problem hiding this comment.
I've tested this locally and the fix works perfectly fine! Thanks for fixing this. Have a minor comment above.
|
|
||
| if request.config.getoption('--disable-socket'): | ||
| request.getfixturevalue('socket_disabled') | ||
|
|
There was a problem hiding this comment.
any comments how this fixes the issue? (if there is an ordering dependency we should probably add comments explaining it)
There was a problem hiding this comment.
It's an ordering issue. The things higher on this list have lower priority. The last thing to set the fixture value wins.
Generally for the purposes in which someone would be using this package (IMHO), people expect more granular settings to have highest priority.
I.E. a marker on a particular function overrides the global disable flag.
This is also the documented and expected behavior; the readme states:
To enable specific tests use of socket, pass in the fixture to the test or use a marker
I can add a bit of comments to the function here.
A few tests for enabled sockets had inverted success criteria. Issue miketheman#15 is resolved by prioritizing the pytest markers over the CLI config. Signed-off-by: Calvin Behling <[email protected]>
|
Huh. That was not what I intended to do. |
|
Code Climate has analyzed commit 53b035b and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (50% is the threshold). This pull request will bring the total coverage in the repository to 95.0% (0.0% change). View more on Code Climate. |
|
LGTM |
|
Hey y'all - taking a look at this today, and I'm confirming the findings y'all have produced - thanks for engaging and clarifying. I think the mismatch crept in a larger-than-desirable refactor three years ago, and I've been behind on managing this project. While diagnosing this, I'm continuing to think about the concept of "order" and how to resolve the approach of overrides - so I'm looking to pytest to find other patterns that combine the idea of |
As reported in a couple of issues, the usage of markers (not fixtures) was misbehaving, as the order in which the `_socket_marker` evaluation was occurring left the command-line option disabled. Fixes #15 Closes #28 Co-authored-by: Calvin Behling <[email protected]> Signed-off-by: Albert Tugushev <[email protected]> Signed-off-by: Matt Callaghan <[email protected]> Signed-off-by: Mike Fiedler <[email protected]>
As reported in a couple of issues, the usage of markers (not fixtures) was misbehaving, as the order in which the `_socket_marker` evaluation was occurring left the command-line option disabled. Fixes #15 Closes #28 Co-authored-by: Calvin Behling <[email protected]> Signed-off-by: Albert Tugushev <[email protected]> Signed-off-by: Matt Callaghan <[email protected]> Signed-off-by: Mike Fiedler <[email protected]>
|
Thanks for the notes and help here! I've incorporated these changes with slight modifications to the language in #42 and released on pypi as version 0.3.5 |
A few tests for enabled sockets had inverted success criteria.
Issue #15 is resolved by prioritizing the pytest markers over the CLI config.