pip list from the virtual environment you are usingDo you have a project or something where we can reproduce this? FWIW collecting 8000 tests takes around 4s here.
what type of code do you need me to share? I am mainly using the "@pytest.mark.parametrize" way of inserting data into the tests, and also using the:
@pytest.mark.CI way of marking tests, although the long collection time happens also when not using the -m CI.
I am doing this before actually running the pytest line:
PYENV_HOME= xxxxxxxx
python3.6 -m venv PYENV_HOME --system-site-packages
. PYENV_HOME/bin/activate
and lastly:
python3.6 -m pytest -m CI --tb=short --jira -v -s
Ideally, a full project where we can run pytest and see the issue. Since this doesn't happen to other people, it's probably something specific to your code.
Alternatively, you could run something like python3 -m cProfile -m pytest --collect-only to (hopefully) see what's the culprit.
when running the above I get:
cProfile.py: error: no such option: -m
if doing:
pip3 install pytest-profiling
and running:
python3.6 -m pytest -m CI --collect-only --profile
I get an empty prof directory...
any idea?
Oh, looks like -m for cProfile was added in Python 3.7. You could probably do something like python3 -m cProfile $(which pytest) --collect-only.
plz see the following profile file and let me know where to start look at. It takes 10min just to collect the 1800 tests
profile-CI.txt
Looking at that profile, something is doing network requests at import time. See e.g.:
46 0.001 0.000 339.007 7.370 adapters.py:394(send)
46 0.001 0.000 339.311 7.376 api.py:104(post)
46 0.001 0.000 339.268 7.375 sessions.py:466(request)
46 0.002 0.000 339.025 7.370 sessions.py:617(send)
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 41.799 41.799 test_aws_egress_only_internet_gateway.py:1(<module>)
1 0.000 0.000 0.479 0.479 test_aws_instances.py:1(<module>)
1 0.000 0.000 40.784 40.784 test_aws_internet_gateway.py:1(<module>)
1 0.000 0.000 0.538 0.538 test_aws_nat_gateway.py:1(<module>)
1 0.000 0.000 39.994 39.994 test_aws_network_acl.py:1(<module>)
1 0.000 0.000 0.504 0.504 test_aws_network_interface.py:1(<module>)
1 0.000 0.000 40.699 40.699 test_aws_route_tables.py:1(<module>)
1 0.000 0.000 0.540 0.540 test_aws_security_groups.py:1(<module>)
1 0.000 0.000 1.356 1.356 test_aws_subnets.py:1(<module>)
1 0.000 0.000 16.470 16.470 test_aws_vpc.py:1(<module>)
1 0.000 0.000 15.466 15.466 test_aws_vpc_peering_connection.py:1(<module>)
1 0.000 0.000 7.274 7.274 test_aws_vpn_connection.py:1(<module>)
1 0.000 0.000 0.512 0.512 test_aws_vpn_gateway.py:1(<module>)
1 0.000 0.000 10.962 10.962 test_azure_crud_credentials.py:1(<module>)
1 0.000 0.000 36.597 36.597 test_azure_firewalls.py:1(<module>)
1 0.000 0.000 30.940 30.940 test_azure_network_interfaces.py:1(<module>)
1 0.000 0.000 10.568 10.568 test_azure_route_tables.py:1(<module>)
1 0.000 0.000 41.044 41.044 test_azure_security_groups.py:1(<module>)
1 0.000 0.000 40.799 40.799 test_azure_vms.py:1(<module>)
1 0.000 0.000 16.122 16.122 test_azure_vnets_subnets.py:1(<module>)
1 0.000 0.000 24.853 24.853 test_azure_vpn_gateways.py:1(<module>)
Filtering the profile output for lines containing test_aws_ or test_azure_ will probably narrow this down enough to spot the function(s) making collection-time network requests.
I don't think this is a pytest bug though, so I'll close the issue.
Most helpful comment
Looking at that profile, something is doing network requests at import time. See e.g.: