I'm using py.test and I want to get the list of tests that I have with marker info included.
When I use the **--collect-only** flag I get the test functions. Is there a way to get the assigned markers for each test also?

---

Based on **Frank T**'s answer I created a workaround code sample:

```
from _pytest.mark import MarkInfo, MarkDecorator
import json

def pytest_addoption(parser):
    parser.addoption(
        '--collect-only-with-markers',
        action='store_true',
        help='Collect the tests with marker information without executing them'
    )

def pytest_collection_modifyitems(session, config, items):
    if config.getoption('--collect-only-with-markers'):
        for item in items:
            data = {}

            # Collect some general information
            if item.cls:
                data['class'] = item.cls.__name__
            data['name'] = item.name
            if item.originalname:
                data['originalname'] = item.originalname
            data['file'] = item.location[0]

            # Get the marker information
            for key, value in item.keywords.items():
                if isinstance(value, (MarkDecorator, MarkInfo)):
                    if 'marks' not in data:
                        data['marks'] = []

                    data['marks'].append(key)

            print(json.dumps(data))

        # Remove all items (we don't want to execute the tests)
        items.clear()

```