Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test-tmpl: &test-tmpl

job-tmpl: &job-tmpl
machine:
image: ubuntu-2004:edge
image: ubuntu-2204:current
Copy link
Author

Choose a reason for hiding this comment

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

Basically ubuntu 20 is unsupported


working_directory: /home/circleci/src

Expand Down
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## Changelog
### 1.9.0
* All: Update `make test` runner to use `pytest` instead of deprecated `setup.py test`
* pytest-profile: add support for `cProfile` regex to filter output
* pytest-profile: update README.md args

### 1.8.1 (2024-11-29)
* All: Add a CircleCI Windows build with py3.6-py3.12 and remove references to TravisCI. (#246)
* All: Add Ubuntu builds for py3.6-3.13
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ develop: copyfiles extras

test:
rm -f FAILED-*
./foreach.sh 'DEBUG=1 python setup.py test -sv -ra || touch ../FAILED-$$PKG'
./foreach.sh 'DEBUG=1 python -m pytest -sv -ra || touch ../FAILED-$$PKG'
bash -c "! compgen -G 'FAILED-*'"

test-ci:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.1
1.9.0
51 changes: 29 additions & 22 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,33 @@ function install_python_ppa {
function install_python_packaging {
local py=$1
$py -m pip install --upgrade pip
$py -m pip install --upgrade setuptools
$py -m pip install --upgrade setuptools wheel
$py -m pip install --upgrade packaging
$py -m pip install --upgrade virtualenv
}


function install_python {
local py=$1
sudo apt-get install -y $py $py-dev
sudo apt-get install -y $py
Copy link
Author

Choose a reason for hiding this comment

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

deadsnakes-ppa py3.6 is no longer supported, apt-get install succeeds with no op.

local version=$(echo $py | grep -oP '(?<=python)\d+\.\d+')

if [ "$version" = "3.6" ] || [ "$version" = "3.7" ]; then
sudo apt-get install ${py}-distutils || {
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/pip/$version/get-pip.py | sudo $py
sudo $py -m pip install setuptools
}
elif [ "$version" = "3.10" ] || [ "$version" = "3.11" ] || [ "$version" = "3.12" ]; then
sudo apt-get install ${py}-distutils
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo $py
else
sudo apt-get install ${py}
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo $py
fi
case $version in
"3.6" | "3.7" | "3.8" | "3.9" )
sudo apt-get install -y $py-distutils
;;
*)
echo ""
;;
esac

case $version in
"3.6" | "3.7" | "3.8" )
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/pip/$version/get-pip.py | sudo $py
;;
*)
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo $py
;;
esac
install_python_packaging $py
}

Expand Down Expand Up @@ -92,7 +97,7 @@ function install_windows_python() {

function init_venv {
local py=$1
virtualenv venv --python=$py
$py -m virtualenv venv
if [ -f venv/Scripts/activate ]; then
. venv/Scripts/activate
else
Expand All @@ -106,11 +111,13 @@ function update_apt_sources {
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | gpg --dearmor -o /usr/share/keyrings/jenkins-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/jenkins-archive-keyring.gpg] https://pkg.jenkins.io/debian-stable binary/" | tee /etc/apt/sources.list.d/jenkins.list > /dev/null

# Add MongoDB GPG key and repository
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
--dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
MONGODB_MAJOR="8.0"
MONGODB_MINOR="8.2"
curl -fsSL https://www.mongodb.org/static/pgp/server-${MONGODB_MAJOR}.asc | \
gpg -o /usr/share/keyrings/mongodb-server-${MONGODB_MAJOR}.gpg \
--dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-${MONGODB_MAJOR}.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/${MONGODB_MINOR} multiverse" | tee /etc/apt/sources.list.d/mongodb-org-${MONGODB_MINOR}.list


apt install ca-certificates
apt-get update
Expand Down Expand Up @@ -145,7 +152,7 @@ function install_jenkins {
}

function install_mongodb {
apt-get install -y mongodb mongodb-server
apt-get install -y mongodb-org
}

function install_apache {
Expand Down
16 changes: 12 additions & 4 deletions pytest-profiling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Install using your favourite package installer:
# or
easy_install pytest-profiling
```

Enable the fixture explicitly in your tests or conftest.py (not required when using setuptools entry points):

```python
Expand All @@ -31,9 +31,17 @@ Once installed, the plugin provides extra options to pytest:
$ py.test --help
...
Profiling:
--profile generate profiling information
--profile-svg generate profiling graph (using gprof2dot and dot
-Tsvg)
--profile generate profiling information
--profile-svg generate profiling graph (using gprof2dot and dot -Tsvg)
--pstats-dir=PSTATS_DIR
configure the dump directory of profile data files
--element-number=ELEMENT_NUMBER
defines how many elements will display in a result
--element-regex=ELEMENT_REGEX
filters elements displayed using regex
--strip-dirs configure to show/hide the leading path information from
file names

```

The ``--profile`` and ``profile-svg`` options can be combined with any other option:
Expand Down
15 changes: 12 additions & 3 deletions pytest-profiling/pytest_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ class Profiling(object):
dot_cmd = None
gprof2dot_cmd = None

def __init__(self, svg, dir=None, element_number=20, stripdirs=False):
def __init__(self, svg, dir=None, element_number=20, stripdirs=False, element_regex=None):
self.svg = svg
self.dir = 'prof' if dir is None else dir[0]
self.stripdirs = stripdirs
self.element_number = element_number
self.element_regex = element_regex
self.profs = []
self.gprof2dot = os.path.abspath(os.path.join(os.path.dirname(sys.executable), 'gprof2dot'))
if not os.path.isfile(self.gprof2dot):
Expand Down Expand Up @@ -98,7 +99,12 @@ def pytest_terminal_summary(self, terminalreporter):
stats = pstats.Stats(self.combined, stream=terminalreporter)
if self.stripdirs:
stats.strip_dirs()
stats.sort_stats('cumulative').print_stats(self.element_number)
if self.element_regex:
print_args = self.element_regex, self.element_number
else:
print_args = (self.element_number,)
stats.sort_stats('cumulative')
stats.print_stats(*print_args)
if self.svg_name:
if not self.exit_code:
# 0 - SUCCESS
Expand Down Expand Up @@ -144,6 +150,8 @@ def pytest_addoption(parser):
help="generate profiling graph (using gprof2dot and dot -Tsvg)")
group.addoption("--pstats-dir", nargs=1,
help="configure the dump directory of profile data files")
group.addoption("--profile-element-regex", type=str, default=None,
help="filters elements displayed using regex")
group.addoption("--element-number", action="store", type=int, default=20,
help="defines how many elements will display in a result")
group.addoption("--strip-dirs", action="store_true",
Expand All @@ -157,4 +165,5 @@ def pytest_configure(config):
config.pluginmanager.register(Profiling(config.getvalue('profile_svg'),
config.getvalue('pstats_dir'),
element_number=config.getvalue('element_number'),
stripdirs=config.getvalue('strip_dirs')))
stripdirs=config.getvalue('strip_dirs'),
element_regex=config.getvalue('profile_element_regex')))
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os


def test_regex():
os.makedirs("bar", exist_ok=True)
os.chdir("bar")
14 changes: 14 additions & 0 deletions pytest-profiling/tests/integration/test_profile_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@ def test_profile_chdir(pytestconfig, virtualenv):
pytestconfig,
cd=virtualenv.workspace,
)


def test_profile_limited_output(pytestconfig, virtualenv):
element_args = ["--element-number=2", r'--profile-element-regex=.*(test_regex|makedirs).*']
# element_args = ["--element-number=100"]
print(["-m", "pytest", "--profile", *element_args, "tests/unit/test_regex.py"])
output = virtualenv.run_with_coverage(
["-m", "pytest", "--profile", *element_args, "tests/unit/test_regex.py"],
pytestconfig,
cd=virtualenv.workspace,
)
assert "test_regex.py:4(test_regex)" in output
assert "makedirs" in output
assert "chdir" not in output
4 changes: 4 additions & 0 deletions pytest-profiling/tests/unit/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def test_adds_options():
group = parser.getgroup.return_value
group.addoption.assert_any_call("--profile", action="store_true", help=ANY)
group.addoption.assert_any_call("--profile-svg", action="store_true", help=ANY)
group.addoption.assert_any_call("--pstats-dir", nargs=1, help=ANY)
group.addoption.assert_any_call("--profile-element-regex", type=str, default=None, help=ANY)
group.addoption.assert_any_call("--element-number", action="store", type=int, default=20, help=ANY)
group.addoption.assert_any_call("--strip-dirs", action="store_true", help=ANY)


def test_configures():
Expand Down
1 change: 0 additions & 1 deletion pytest-server-fixtures/pytest_server_fixtures/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def get_args(self, **kwargs):
'--port=%s' % self.port,
'--nounixsocket',
'--syncdelay=0',
'--nojournal',
Copy link
Author

Choose a reason for hiding this comment

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

Unsupported anymore

'--quiet',
]

Expand Down
37 changes: 12 additions & 25 deletions pytest-virtualenv/pytest_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,7 @@ def install_package(self, pkg_name, version=PackageVersion.LATEST, installer="pi
installer += ' -q'

if version == PackageVersion.LATEST:
self.run(
"{python} {installer} {installer_command} {spec}".format(
python=self.python, installer=installer, installer_command=installer_command, spec=pkg_name
)
)
spec = pkg_name
elif version == PackageVersion.CURRENT:
dist = next(
iter([dist for dist in distributions() if _normalize(dist.name) == _normalize(pkg_name)]), None
Expand All @@ -225,31 +221,22 @@ def install_package(self, pkg_name, version=PackageVersion.LATEST, installer="pi
)
egg_link = _get_egg_link(dist.name)
if pkg_location:
self.run(
f"{self.python} {installer} {installer_command} -e {pkg_location}"
)
spec = f" -e {pkg_location}"
elif egg_link:
self._install_package_from_editable_egg_link(egg_link, dist)
return
else:
spec = "{pkg_name}=={version}".format(pkg_name=pkg_name, version=dist.version)
self.run(
"{python} {installer} {installer_command} {spec}".format(
python=self.python, installer=installer, installer_command=installer_command, spec=spec
)
)
setup_files = ["pyproject.toml", "setup.py"]
if any(os.path.exists(dist.locate_file(f)) for f in setup_files):
spec = dist.locate_file("")
else:
spec = f"{pkg_name}=={dist.version}"
else:
self.run(
"{python} {installer} {installer_command} {spec}".format(
python=self.python, installer=installer, installer_command=installer_command, spec=pkg_name
)
)
spec = pkg_name
else:
spec = "{pkg_name}=={version}".format(pkg_name=pkg_name, version=version)
self.run(
"{python} {installer} {installer_command} {spec}".format(
python=self.python, installer=installer, installer_command=installer_command, spec=spec
)
)
spec = f"{pkg_name}=={version}"
cmd = f"{self.python} {installer} {installer_command} {spec}"
self.run(cmd)

def installed_packages(self, package_type=None):
"""
Expand Down