Skip to content

Instantly share code, notes, and snippets.

@zengabor
Last active January 23, 2022 19:16
Show Gist options
  • Save zengabor/5305917 to your computer and use it in GitHub Desktop.
Save zengabor/5305917 to your computer and use it in GitHub Desktop.
**Custom prefix for Python unit test methods** (doing BDD in Python and wanted proper prefixes instead of the default 'test' prefix, and pytest had a bug: https://bitbucket.org/hpk42/pytest/issue/284/python_classes-and-python_functions)
import unittest
unittest.TestLoader.testMethodPrefix = 'should'
from unittest import TestCase as Specification
class MyClass(Specification):
def should_do_something():
"""This method with the 'should' prefix will be picked up by test runners"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment