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

@pytest.mark.enable_socket doesn't work #15

Closed
wimglenn opened this issue Nov 6, 2018 · 4 comments · Fixed by #42
Closed

@pytest.mark.enable_socket doesn't work #15

wimglenn opened this issue Nov 6, 2018 · 4 comments · Fixed by #42
Labels
bug Something isn't working

Comments

@wimglenn
Copy link

wimglenn commented Nov 6, 2018

The mark to enable_socket doesn't seem to work. The fixture socket_enabled still works.

pytest-socket==0.3.1
pytest==3.10.0

Tried also on pytest==3.6.3 (earliest version supported according to pytest-socket metadata), same result.

MCVE test_something.py:

import socket
import pytest

def f():
    socket.socket()

@pytest.mark.enable_socket
def test_1():
    f()

def test_2(socket_enabled):
    f()

Demo:

$ pytest --disable-socket -v
======================================= test session starts =======================================
platform linux -- Python 3.7.0, pytest-3.10.0, py-1.7.0, pluggy-0.8.0 -- /tmp/example/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /tmp/example, inifile:
plugins: socket-0.3.1
collected 2 items                                                                                 

test_something.py::test_1 FAILED                                                            [ 50%]
test_something.py::test_2 PASSED                                                            [100%]

============================================ FAILURES =============================================
_____________________________________________ test_1 ______________________________________________

    @pytest.mark.enable_socket
    def test_1():
>       f()

test_something.py:9: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test_something.py:5: in f
    socket.socket()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = (), kwargs = {}

    def guarded(*args, **kwargs):
>       raise SocketBlockedError()
E       pytest_socket.SocketBlockedError: A test tried to use socket.socket.

.venv/lib/python3.7/site-packages/pytest_socket.py:72: SocketBlockedError
=============================== 1 failed, 1 passed in 0.04 seconds ================================```
@wimglenn
Copy link
Author

wimglenn commented Nov 6, 2018

There seems to be a test for this:

https://github.com/miketheman/pytest-socket/blob/0.3.1/tests/test_socket.py#L104-L115

But it looks like it's asserting on the exact opposite of what it should be asserting..

@miketheman miketheman added the bug Something isn't working label Dec 14, 2018
TripleDogDare added a commit to TripleDogDare/pytest-socket that referenced this issue Jul 16, 2019
A few tests for enabled sockets had inverted success criteria.
Issue miketheman#15 is resolved by prioritizing the pytest markers over the CLI config.
TripleDogDare added a commit to TripleDogDare/pytest-socket that referenced this issue Jul 16, 2019
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 <calvin.behling@gmail.com>
@mcallaghan-bsm
Copy link

mcallaghan-bsm commented Nov 7, 2019

@miketheman - any update on #28 ? :) would be nice to fix, we just ran into this

Adding latest information, still an issue with these versions:

pytest                 5.2.2
pytest-socket          0.3.3
Python 3.7.3

@miketheman
Copy link
Owner

I'll try to get to evaluating these scenarios and fix this weekend.

@Alexander3
Copy link

Workaround:

@pytest.mark.enable_socket
@pytest.mark.vcr()
def test_fetch_weather():

gives E pytest_socket.SocketBlockedError: A test tried to use socket.socket.
but

@pytest.mark.vcr()
def test_fetch_weather(socket_enabled):

works

TripleDogDare added a commit to TripleDogDare/pytest-socket that referenced this issue Jan 2, 2020
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 <calvin.behling@gmail.com>
TripleDogDare added a commit to TripleDogDare/pytest-socket that referenced this issue Jan 2, 2020
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 <calvin.behling@gmail.com>
miketheman added a commit that referenced this issue May 31, 2020
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 <calvin.behling@gmail.com>
Signed-off-by: Albert Tugushev <albert@tugushev.ru>
Signed-off-by: Matt Callaghan <mcallaghan-bsm@users.noreply.github.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
miketheman added a commit that referenced this issue May 31, 2020
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 <calvin.behling@gmail.com>
Signed-off-by: Albert Tugushev <albert@tugushev.ru>
Signed-off-by: Matt Callaghan <mcallaghan-bsm@users.noreply.github.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants