Skip to content

Commit

Permalink
Skip tests with pygments version mismatch.
Browse files Browse the repository at this point in the history
If pygments is installed and the version doesn't match the expected version.
then any relevant tests will fail. To avoid failing tests due to different
output by pygments, those tests will be skipped. The pygments tox env
sets the `PYGMENTS_VERSION environment variable, so that env will always
run those tests against the expected version.
  • Loading branch information
waylan committed Oct 8, 2020
1 parent 6525e21 commit e02ed39
Show file tree
Hide file tree
Showing 2 changed files with 282 additions and 261 deletions.
14 changes: 14 additions & 0 deletions tests/test_syntax/extensions/test_code_hilite.py
Expand Up @@ -21,17 +21,27 @@

from markdown.test_tools import TestCase
from markdown.extensions.codehilite import CodeHiliteExtension, CodeHilite
import os

try:
import pygments # noqa
has_pygments = True
except ImportError:
has_pygments = False

# The version required by the tests is the version specified and installed in the 'pygments' tox env.
# In any environment where the PYGMENTS_VERSION environment variabe is either not defined or doesn't
# match the version of Pygments installed, all tests which rely in pygments will be skipped.
required_pygments_version = os.environ.get('PYGMENTS_VERSION', '')


class TestCodeHiliteClass(TestCase):
""" Test the markdown.extensions.codehilite.CodeHilite class. """

def setUp(self):
if has_pygments and pygments.__version__ != required_pygments_version:
self.skipTest(f'Pygments=={required_pygments_version} is required')

maxDiff = None

def assertOutputEquals(self, source, expected, **options):
Expand Down Expand Up @@ -340,6 +350,10 @@ def test_codehilite_startinline(self):
class TestCodeHiliteExtension(TestCase):
""" Test codehilite extension. """

def setUp(self):
if has_pygments and pygments.__version__ != required_pygments_version:
self.skipTest(f'Pygments=={required_pygments_version} is required')

maxDiff = None

def testBasicCodeHilite(self):
Expand Down

0 comments on commit e02ed39

Please sign in to comment.