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

Use pytest instead of unittest #628

Merged
merged 18 commits into from
Jun 21, 2024
Merged
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
23 changes: 0 additions & 23 deletions .github/workflows/coverage.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ jobs:
- name: Install pydeps
run: |
python.exe -m pip install --upgrade --user setuptools pip wheel
python.exe -m pip install --upgrade mock ipaddress pypiwin32 wmi pyopenssl psutil
python.exe -m pip install --upgrade mock ipaddress pypiwin32 wmi pyopenssl psutil pytest
python.exe -m pip freeze
python.exe setup.py install

- name: Tests
run: |
python.exe pyftpdlib/test/runner.py
make test

# Run linters
linters:
Expand Down
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Version: 1.5.10 - (UNRELEASED)

* #621: use black formatter.
* #626: use argparse instead of deprecated optparse.
* #628: use pytest instead of unittest.

Version: 1.5.9 - 2023-10-25
===========================
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ include pyftpdlib/servers.py
include pyftpdlib/test/README
include pyftpdlib/test/__init__.py
include pyftpdlib/test/keycert.pem
include pyftpdlib/test/runner.py
include pyftpdlib/test/test_authorizers.py
include pyftpdlib/test/test_filesystems.py
include pyftpdlib/test/test_functional.py
Expand Down
28 changes: 17 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# $ make install PYTHON=python3.7

PYTHON = python3
TSCRIPT = pyftpdlib/test/runner.py
ARGS =
PYDEPS = \
black \
Expand All @@ -12,6 +11,8 @@ PYDEPS = \
psutil \
pylint \
pyopenssl \
pytest \
pytest-cov \
rstcheck \
ruff \
setuptools \
Expand All @@ -32,6 +33,7 @@ endif
# In not in a virtualenv, add --user options for install commands.
INSTALL_OPTS = `$(PYTHON) -c "import sys; print('' if hasattr(sys, 'real_prefix') else '--user')"`
TEST_PREFIX = PYTHONWARNINGS=always
PYTEST_ARGS = -v --tb=native -o cache_dir=/tmp/pyftpdlib-pytest-cache
NUM_WORKERS = `$(PYTHON) -c "import os; print(os.cpu_count() or 1)"`


Expand Down Expand Up @@ -110,40 +112,44 @@ setup-dev-env: ## Install GIT hooks, pip, test deps (also upgrades them).

test: ## Run all tests. To run a specific test: do "make test ARGS=pyftpdlib.test.test_functional.TestFtpStoreData"
${MAKE} install
$(TEST_PREFIX) $(PYTHON) $(TSCRIPT) $(ARGS)
$(TEST_PREFIX) $(PYTHON) -m pytest $(PYTEST_ARGS) $(ARGS)

test-functional: ## Run functional FTP tests.
${MAKE} install
$(TEST_PREFIX) $(PYTHON) pyftpdlib/test/test_functional.py
$(TEST_PREFIX) $(PYTHON) -m pytest $(PYTEST_ARGS) $(ARGS) pyftpdlib/test/test_functional.py

test-functional-ssl: ## Run functional FTPS tests.
${MAKE} install
$(TEST_PREFIX) $(PYTHON) pyftpdlib/test/test_functional_ssl.py
$(TEST_PREFIX) $(PYTHON) -m pytest $(PYTEST_ARGS) $(ARGS) pyftpdlib/test/test_functional_ssl.py

test-servers: ## Run tests for FTPServer and its subclasses.
${MAKE} install
$(TEST_PREFIX) $(PYTHON) pyftpdlib/test/test_servers.py
$(TEST_PREFIX) $(PYTHON) -m pytest $(PYTEST_ARGS) $(ARGS) pyftpdlib/test/test_servers.py

test-authorizers: ## Run tests for authorizers.
${MAKE} install
$(TEST_PREFIX) $(PYTHON) pyftpdlib/test/test_authorizers.py
$(TEST_PREFIX) $(PYTHON) -m pytest $(PYTEST_ARGS) $(ARGS) pyftpdlib/test/test_authorizers.py

test-filesystems: ## Run filesystem tests.
${MAKE} install
$(TEST_PREFIX) $(PYTHON) pyftpdlib/test/test_filesystems.py
$(TEST_PREFIX) $(PYTHON) -m pytest $(PYTEST_ARGS) $(ARGS) pyftpdlib/test/test_filesystems.py

test-ioloop: ## Run IOLoop tests.
${MAKE} install
$(TEST_PREFIX) $(PYTHON) pyftpdlib/test/test_ioloop.py
$(TEST_PREFIX) $(PYTHON) -m pytest $(PYTEST_ARGS) $(ARGS) pyftpdlib/test/test_ioloop.py

test-misc: ## Run miscellaneous tests.
${MAKE} install
$(TEST_PREFIX) $(PYTHON) pyftpdlib/test/test_misc.py
$(TEST_PREFIX) $(PYTHON) -m pytest $(PYTEST_ARGS) $(ARGS) pyftpdlib/test/test_misc.py

test-lastfailed: ## Run previously failed tests
${MAKE} install
$(TEST_PREFIX) $(PYTHON) -m pytest $(PYTEST_ARGS) --last-failed $(ARGS)

test-coverage: ## Run test coverage.
${MAKE} install
rm -rf .coverage htmlcov
PYTHONWARNINGS=all $(PYTHON) -m coverage run $(TSCRIPT)
$(TEST_PREFIX) $(PYTHON) -m coverage run -m pytest $(PYTEST_ARGS) $(ARGS)
$(PYTHON) -m coverage report
@echo "writing results to htmlcov/index.html"
$(PYTHON) -m coverage html
Expand Down Expand Up @@ -182,7 +188,7 @@ fix-black:
git ls-files '*.py' | xargs $(PYTHON) -m black

fix-ruff:
@git ls-files '*.py' | xargs $(PYTHON) -m ruff --config=pyproject.toml --no-cache --fix $(ARGS)
@git ls-files '*.py' | xargs $(PYTHON) -m ruff check --no-cache --fix $(ARGS)

fix-toml: ## Fix pyproject.toml
@git ls-files '*.toml' | xargs toml-sort
Expand Down
6 changes: 1 addition & 5 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
| |downloads| |stars| |forks| |contributors| |coverage|
| |downloads| |stars| |forks| |contributors|
| |version| |packages| |license|
| |github-actions| |appveyor| |doc| |twitter|

Expand Down Expand Up @@ -26,10 +26,6 @@
:target: https://ci.appveyor.com/project/giampaolo/pyftpdlib
:alt: Windows (Py2, Windows)

.. |coverage| image:: https://img.shields.io/codecov/c/github/giampaolo/pyftpdlib/update-ci?label=coverage
:target: https://codecov.io/gh/giampaolo/pyftpdlib
:alt: Test coverage

.. |doc| image:: https://readthedocs.org/projects/pyftpdlib/badge/?version=latest
:target: https://pyftpdlib.readthedocs.io/en/latest/
:alt: Documentation Status
Expand Down
2 changes: 1 addition & 1 deletion pyftpdlib/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def assert_free_resources(parent_pid=None):
if POSIX:
cons = [
x
for x in this_proc.connections('tcp')
for x in this_proc.net_connections('tcp')
if x.status != psutil.CONN_CLOSE_WAIT
]
if cons:
Expand Down
Loading
Loading