How to use pytest_make_parametrize_id method in Pytest

Best Python code snippet using pytest

pytest_plugin.py

Source:pytest_plugin.py Github

copy

Full Screen

1from django_xss_fuzzer import DEFAULT_PATTERNS2def pytest_generate_tests(metafunc):3 if "xss_pattern" in metafunc.fixturenames:4 metafunc.parametrize("xss_pattern", DEFAULT_PATTERNS)5def pytest_make_parametrize_id(config, val, argname):6 if argname == "xss_pattern":...

Full Screen

Full Screen

conftest.py

Source:conftest.py Github

copy

Full Screen

1def pytest_make_parametrize_id(val):...

Full Screen

Full Screen

StackOverFlow community discussions

Questions
Discussion

Use docstrings to list tests in py.test

How to set argparse arguments from python script

Dealing with multiple Python versions and PIP?

Custom exceptions in unittests

How pylint-pytest throws F6401 Can-enumerate-pytest-fixtures

How to POST JSON data with Python Requests?

How do I type hint a method with the type of the enclosing class?

No module named 'scipy.sparse._sparsetools'

Does Python have a ternary conditional operator?

How to modify failure report for specific tests

To expand on my comment to @michael-wan's answer: to achive something similar to specplugin put into conftest.py:

def pytest_itemcollected(item):
    par = item.parent.obj
    node = item.obj
    pref = par.__doc__.strip() if par.__doc__ else par.__class__.__name__
    suf = node.__doc__.strip() if node.__doc__ else node.__name__
    if pref or suf:
        item._nodeid = ' '.join((pref, suf))

and the pytest output of

class TestSomething:
"""Something"""

def test_ok(self):
    """should be ok"""
    pass

will look like

py.test screen grab

If you omit docstrings class/func names will be used.

https://stackoverflow.com/questions/28898919/use-docstrings-to-list-tests-in-py-test

Blogs

Check out the latest blogs from LambdaTest on this topic:

Python Testing Tutorial: Why Python for Test Automation

This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Selenium Python Tutorial.

19 Best Cross Browser Testing Hacks For Faster Release

This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Cross Browser Testing Tutorial.

Pytest Tutorial: Executing Multiple Test Cases From Single File

This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Selenium pytest Tutorial.

Selenium Python Tutorial: A Python Automation Testing Guide with examples

Python is a programming language that needs no introduction! It is one of the most preferred languages when it comes to projects involving Machine Learning (ML), Artificial Intelligence(AI), and more. On a different battleground, the combination of Selenium Python is widely preferred as far as website automation is concerned.

Debunking The Top 8 Selenium Testing Myths

When it comes to web automation testing, the first automation testing framework that comes to mind undoubtedly has to be the Selenium framework. Selenium automation testing has picked up a significant pace since the creation of the framework way back in 2004.

Pytest Tutorial

Looking for an in-depth tutorial around pytest? LambdaTest covers the detailed pytest tutorial that has everything related to the pytest, from setting up the pytest framework to automation testing. Delve deeper into pytest testing by exploring advanced use cases like parallel testing, pytest fixtures, parameterization, executing multiple test cases from a single file, and more.

Chapters

  1. What is pytest
  2. Pytest installation: Want to start pytest from scratch? See how to install and configure pytest for Python automation testing.
  3. Run first test with pytest framework: Follow this step-by-step tutorial to write and run your first pytest script.
  4. Parallel testing with pytest: A hands-on guide to parallel testing with pytest to improve the scalability of your test automation.
  5. Generate pytest reports: Reports make it easier to understand the results of pytest-based test runs. Learn how to generate pytest reports.
  6. Pytest Parameterized tests: Create and run your pytest scripts while avoiding code duplication and increasing test coverage with parameterization.
  7. Pytest Fixtures: Check out how to implement pytest fixtures for your end-to-end testing needs.
  8. Execute Multiple Test Cases: Explore different scenarios for running multiple test cases in pytest from a single file.
  9. Stop Test Suite after N Test Failures: See how to stop your test suite after n test failures in pytest using the @pytest.mark.incremental decorator and maxfail command-line option.

YouTube

Skim our below pytest tutorial playlist to get started with automation testing using the pytest framework.

https://www.youtube.com/playlist?list=PLZMWkkQEwOPlcGgDmHl8KkXKeLF83XlrP

Run Pytest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful