Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Only run tests marked with @pytest.mark.only
. If none are marked, all tests run as usual.
Borrowed from mocha <https://mochajs.org/>
_.
.. code-block:: bash
pip install pytest-only
Use it on functions
.. code-block:: python
import pytest
def test_that_will_not_run():
assert 0
@pytest.mark.only
def test_that_will_run():
assert 1
.. code-block:: bash
$ py.test -v test_example.py
============================= test session starts ==============================
platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /tmp/example/bin/python3.6
cachedir: .cache
rootdir: /tmp/example, inifile:
plugins: only-1.0.0
collected 2 items
test_example.py::test_that_will_run PASSED
=========================== 1 passed in 0.00 seconds ===========================
Or use it on classes
.. code-block:: python
import pytest
class TestThatWillNotRun:
def test_that_will_not_run(self):
assert 0
@pytest.mark.only
class TestThatWillRun:
def test_that_will_run(self):
assert 1
.. code-block:: bash
$ py.test -v test_example.py
============================= test session starts ==============================
platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /tmp/example/bin/python3.6
cachedir: .cache
rootdir: /tmp/example, inifile:
plugins: only-1.0.0
collected 2 items
test_example.py::TestThatWillRun::test_that_will_run PASSED
=========================== 1 passed in 0.00 seconds ===========================
Or use it on modules
.. code-block:: python
# test_example.py
import pytest
pytestmark = pytest.mark.only
def test_that_will_run():
assert 1
.. code-block:: python
# test_example2.py
def test_that_will_not_run():
assert 0
.. code-block:: bash
$ py.test -v test_example.py test_example2.py
============================= test session starts ==============================
platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /home/they4kman/.virtualenvs/tmp-53d5944c7c78d28/bin/python3.6
cachedir: .cache
rootdir: /home/they4kman/.virtualenvs/tmp-53d5944c7c78d28, inifile:
plugins: only-1.0.0
collected 2 items
test_example.py::test_that_will_run PASSED
=========================== 1 passed in 0.00 seconds ===========================
To run all the tests, regardless of whether @pytest.mark.only
is used, pass
the --no-only
flag to pytest:
.. code-block:: bash
$ py.test --no-only
If --no-only
has already been passed (perhaps by way of addopts
in
pytest.ini), use the --only
flag to re-enable it:
.. code-block:: bash
$ py.test --no-only --only
If you use pylint, you can avoid committing stray only
marks with the bundled plugin. Just enable the pylint checker in your plugins and enable the unexpected-focused
rule.
.. code-block:: ini
[MASTER]
load-plugins=pytest_only.ext.pylint
[MESSAGES CONTROL]
enable=unexpected-focused
.. code-block:: console
$ cat test_ninja.py
import pytest
@pytest.mark.only
def test_ninja():
pass
$ pylint test_ninja.py
************* Module mymain
test_ninja.py:3:0: W1650: Unexpected focused test(s) using pytest.mark.only: def test_ninja (unexpected-focused)
Install the test/dev requirements using Poetry <https://python-poetry.org/>
_
.. code-block:: bash
poetry install
Run the tests
.. code-block:: bash
py.test
Run the tests on all currently-supported platforms
.. code-block:: bash
tox
FAQs
Use @pytest.mark.only to run a single test
We found that pytest-only demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.