Comments (6)
Already filed a bug there since I could recreate with just it. Link above. I'll follow up there if I manage any more debugging.
from pytest-monitor.
Hello @altendky
Thanks for the time spent on this. However, I am unsure to get it right.
You already bind your socket in your fixture and try to rebind it in your test. In your fixture, the where will be evaluated to 'fixture' and is then returned to the stack in your test. Thus, you bind twice the same object.
Additionally, you probably want to close your socket after the yield statement in your fixture.
Please correct me if I misunderstood your problem.
from pytest-monitor.
Before rebinding to the port, in either case, the first socket is closed. Looking at the pytest output in the full session it shows that the second parametrization where the socket is created in the test there is no error (be sure to expand the collapsed sections in the OP and below here). Closing the socket in the fixture during teardown would normally make sense, but it isn't relevant to this example since it would occur after the error. Note that the failing test with the socket from the fixture is run first so it can't be caused by an issue not closing the socket from the passing case which is second.
I probably shouldn't have parametrized the tests. Here's a more explicit non-parametrized recreation.
import socket
import subprocess
import pytest
address = ("127.0.0.1", 33125)
@pytest.fixture(scope="function")
def just_a_socket():
sock = socket.socket()
sock.bind(address)
yield sock
sock.close()
def test_a_socket_from_a_fixture(just_a_socket):
sock = just_a_socket
sock.close()
sock2 = socket.socket()
sock2.bind(address)
def test_a_socket_from_the_test():
sock = socket.socket()
sock.bind(address)
sock.close()
sock2 = socket.socket()
sock2.bind(address)
sock.close()
def main():
subprocess.run(["pytest", "--capture", "no", "--verbose", __file__], check=True)
# yuck
if __name__ == "__main__":
main()
commands
cat > x.py << EOF
import socket
import subprocess
import pytest
address = ("127.0.0.1", 33125)
@pytest.fixture(scope="function")
def just_a_socket():
sock = socket.socket()
sock.bind(address)
yield sock
sock.close()
def test_a_socket_from_a_fixture(just_a_socket):
sock = just_a_socket
sock.close()
sock2 = socket.socket()
sock2.bind(address)
def test_a_socket_from_the_test():
sock = socket.socket()
sock.bind(address)
sock.close()
sock2 = socket.socket()
sock2.bind(address)
sock.close()
def main():
subprocess.run(["pytest", "--capture", "no", "--verbose", __file__], check=True)
# yuck
if __name__ == "__main__":
main()
EOF
cat x.py
python3.9 -m venv venv
venv/bin/python --version --version
venv/bin/python -m pip install --upgrade pip setuptools wheel
venv/bin/pip install attrs==21.2.0 iniconfig==1.1.1 packaging==21.3 pluggy==1.0.0 py==1.11.0 pyparsing==3.0.6 pytest==6.2.5 toml==0.10.2
venv/bin/pip freeze
venv/bin/pytest x.py
venv/bin/pip install attrs==21.2.0 certifi==2021.10.8 charset-normalizer==2.0.9 idna==3.3 iniconfig==1.1.1 memory-profiler==0.60.0 packaging==21.3 pluggy==1.0.0 psutil==5.8.0 py==1.11.0 pyparsing==3.0.6 pytest==6.2.5 pytest-monitor==1.6.3 requests==2.26.0 toml==0.10.2 urllib3==1.26.7
venv/bin/pip freeze
venv/bin/pytest x.py
uname -a
lsb_release -a
session
$ cat > x.py << EOF
> import socket
> import subprocess
>
> import pytest
>
>
> address = ("127.0.0.1", 33125)
>
>
> @pytest.fixture(scope="function")
> def just_a_socket():
> sock = socket.socket()
> sock.bind(address)
> yield sock
> sock.close()
>
>
> def test_a_socket_from_a_fixture(just_a_socket):
> sock = just_a_socket
>
> sock.close()
>
> sock2 = socket.socket()
> sock2.bind(address)
>
>
> def test_a_socket_from_the_test():
> sock = socket.socket()
> sock.bind(address)
>
> sock.close()
>
> sock2 = socket.socket()
> sock2.bind(address)
> sock.close()
>
>
> def main():
> subprocess.run(["pytest", "--capture", "no", "--verbose", __file__], check=True)
>
>
> # yuck
> if __name__ == "__main__":
> main()
> EOF
$ cat x.py
import socket
import subprocess
import pytest
address = ("127.0.0.1", 33125)
@pytest.fixture(scope="function")
def just_a_socket():
sock = socket.socket()
sock.bind(address)
yield sock
sock.close()
def test_a_socket_from_a_fixture(just_a_socket):
sock = just_a_socket
sock.close()
sock2 = socket.socket()
sock2.bind(address)
def test_a_socket_from_the_test():
sock = socket.socket()
sock.bind(address)
sock.close()
sock2 = socket.socket()
sock2.bind(address)
sock.close()
def main():
subprocess.run(["pytest", "--capture", "no", "--verbose", __file__], check=True)
# yuck
if __name__ == "__main__":
main()
$ python3.9 -m venv venv
$ venv/bin/python --version --version
Python 3.9.5 (default, Jun 3 2021, 15:18:23)
[GCC 9.3.0]
$ venv/bin/python -m pip install --upgrade pip setuptools wheel
Requirement already satisfied: pip in ./venv/lib/python3.9/site-packages (21.1.1)
Collecting pip
Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
Requirement already satisfied: setuptools in ./venv/lib/python3.9/site-packages (56.0.0)
Collecting setuptools
Using cached setuptools-60.1.0-py3-none-any.whl (952 kB)
Collecting wheel
Using cached wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel, setuptools, pip
Attempting uninstall: setuptools
Found existing installation: setuptools 56.0.0
Uninstalling setuptools-56.0.0:
Successfully uninstalled setuptools-56.0.0
Attempting uninstall: pip
Found existing installation: pip 21.1.1
Uninstalling pip-21.1.1:
Successfully uninstalled pip-21.1.1
Successfully installed pip-21.3.1 setuptools-60.1.0 wheel-0.37.1
$ venv/bin/pip install attrs==21.2.0 iniconfig==1.1.1 packaging==21.3 pluggy==1.0.0 py==1.11.0 pyparsing==3.0.6 pytest==6.2.5 toml==0.10.2
Collecting attrs==21.2.0
Using cached attrs-21.2.0-py2.py3-none-any.whl (53 kB)
Collecting iniconfig==1.1.1
Using cached iniconfig-1.1.1-py2.py3-none-any.whl (5.0 kB)
Collecting packaging==21.3
Using cached packaging-21.3-py3-none-any.whl (40 kB)
Collecting pluggy==1.0.0
Using cached pluggy-1.0.0-py2.py3-none-any.whl (13 kB)
Collecting py==1.11.0
Using cached py-1.11.0-py2.py3-none-any.whl (98 kB)
Collecting pyparsing==3.0.6
Using cached pyparsing-3.0.6-py3-none-any.whl (97 kB)
Collecting pytest==6.2.5
Using cached pytest-6.2.5-py3-none-any.whl (280 kB)
Collecting toml==0.10.2
Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
Installing collected packages: pyparsing, toml, py, pluggy, packaging, iniconfig, attrs, pytest
Successfully installed attrs-21.2.0 iniconfig-1.1.1 packaging-21.3 pluggy-1.0.0 py-1.11.0 pyparsing-3.0.6 pytest-6.2.5 toml-0.10.2
$ venv/bin/pip freeze
attrs==21.2.0
iniconfig==1.1.1
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.0.6
pytest==6.2.5
toml==0.10.2
$ venv/bin/pytest x.py
================================================= test session starts ==================================================
platform linux -- Python 3.9.5, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/altendky/repos/chia-blockchain
collected 2 items
x.py .. [100%]
================================================== 2 passed in 0.01s ===================================================
$ venv/bin/pip install attrs==21.2.0 certifi==2021.10.8 charset-normalizer==2.0.9 idna==3.3 iniconfig==1.1.1 memory-profiler==0.60.0 packaging==21.3 pluggy==1.0.0 psutil==5.8.0 py==1.11.0 pyparsing==3.0.6 pytest==6.2.5 pytest-monitor==1.6.3 requests==2.26.0 toml==0.10.2 urllib3==1.26.7
Requirement already satisfied: attrs==21.2.0 in ./venv/lib/python3.9/site-packages (21.2.0)
Collecting certifi==2021.10.8
Using cached certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
Collecting charset-normalizer==2.0.9
Using cached charset_normalizer-2.0.9-py3-none-any.whl (39 kB)
Collecting idna==3.3
Using cached idna-3.3-py3-none-any.whl (61 kB)
Requirement already satisfied: iniconfig==1.1.1 in ./venv/lib/python3.9/site-packages (1.1.1)
Collecting memory-profiler==0.60.0
Using cached memory_profiler-0.60.0-py3-none-any.whl
Requirement already satisfied: packaging==21.3 in ./venv/lib/python3.9/site-packages (21.3)
Requirement already satisfied: pluggy==1.0.0 in ./venv/lib/python3.9/site-packages (1.0.0)
Collecting psutil==5.8.0
Using cached psutil-5.8.0-cp39-cp39-manylinux2010_x86_64.whl (293 kB)
Requirement already satisfied: py==1.11.0 in ./venv/lib/python3.9/site-packages (1.11.0)
Requirement already satisfied: pyparsing==3.0.6 in ./venv/lib/python3.9/site-packages (3.0.6)
Requirement already satisfied: pytest==6.2.5 in ./venv/lib/python3.9/site-packages (6.2.5)
Collecting pytest-monitor==1.6.3
Using cached pytest_monitor-1.6.3-py3-none-any.whl (14 kB)
Collecting requests==2.26.0
Using cached requests-2.26.0-py2.py3-none-any.whl (62 kB)
Requirement already satisfied: toml==0.10.2 in ./venv/lib/python3.9/site-packages (0.10.2)
Collecting urllib3==1.26.7
Using cached urllib3-1.26.7-py2.py3-none-any.whl (138 kB)
Requirement already satisfied: wheel in ./venv/lib/python3.9/site-packages (from pytest-monitor==1.6.3) (0.37.1)
Installing collected packages: urllib3, psutil, idna, charset-normalizer, certifi, requests, memory-profiler, pytest-monitor
Successfully installed certifi-2021.10.8 charset-normalizer-2.0.9 idna-3.3 memory-profiler-0.60.0 psutil-5.8.0 pytest-monitor-1.6.3 requests-2.26.0 urllib3-1.26.7
$ venv/bin/pip freeze
attrs==21.2.0
certifi==2021.10.8
charset-normalizer==2.0.9
idna==3.3
iniconfig==1.1.1
memory-profiler==0.60.0
packaging==21.3
pluggy==1.0.0
psutil==5.8.0
py==1.11.0
pyparsing==3.0.6
pytest==6.2.5
pytest-monitor==1.6.3
requests==2.26.0
toml==0.10.2
urllib3==1.26.7
$ venv/bin/pytest x.py
================================================= test session starts ==================================================
platform linux -- Python 3.9.5, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/altendky/repos/chia-blockchain
plugins: monitor-1.6.3
collected 2 items
x.py F. [100%]
======================================================= FAILURES =======================================================
_____________________________________________ test_a_socket_from_a_fixture _____________________________________________
just_a_socket = <socket.socket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>
def test_a_socket_from_a_fixture(just_a_socket):
sock = just_a_socket
sock.close()
sock2 = socket.socket()
> sock2.bind(address)
E OSError: [Errno 98] Address already in use
x.py:24: OSError
=============================================== short test summary info ================================================
FAILED x.py::test_a_socket_from_a_fixture - OSError: [Errno 98] Address already in use
============================================= 1 failed, 1 passed in 0.06s ==============================================
$ uname -a
Linux p1 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
from pytest-monitor.
Forcing it to run wrapped_function()
instead of prof()
seems to avoid the problem. So, perhaps I need to bump this over there. I'll see if I can make a recreation just using memory_profiler.memory_usage()
.
pytest-monitor/pytest_monitor/pytest_monitor.py
Lines 157 to 162 in a73b055
from pytest-monitor.
It does appear to be down in memory_profiler
(or below?). pythonprofilers/memory_profiler#342 I would personally leave this open until it is resolved so it is easy to find if anyone else runs into this. But, at the moment, it doesn't look like there's any action needed on your part in terms of fixing this.
from pytest-monitor.
Ok got your point.
My intuition drives me to memory_profiler at first glance since the profiling launches a monitoring process apart. I'll check this out next week...
from pytest-monitor.
Related Issues (20)
- add support for unittests (via pytest) HOT 9
- Provide an option to force garbage collector to run between tests HOT 2
- discuss best memory measurement approach and possible leak detection
- Backend realization HOT 2
- Unable to send measures on monitor-server
- Write monitor-output of tests to console HOT 6
- Incorrect result HOT 6
- pytest.skip() in a fixture causes an AttributeError for monitor_results during teardown HOT 5
- unicode issue in determine_scm_revision with Perforce
- Crash on __init__ if psutil.cpu_freq() gives no results HOT 1
- Running pytest after install pytest-monitor results in `FileNotFoundError: [Errno 2] No such file or directory (originated from sysctl(HW_CPU_FREQ))` HOT 6
- NotImplementedError: can't find current frequency file HOT 4
- Support for newer python versions HOT 1
- Missing metrics for failed tests HOT 8
- Drop python 3.7/pytest 5.*
- Use black and flake8 with pre-commit hooks
- Add Bitbucket CI details to
- Add postgres DB handler
- --no-monitor breaks pytest.raises and django_assert_num_queries HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytest-monitor.