Skip to content

AssertionRewritingHook object returned from pkgutil.get_loader() #2506

@avylove

Description

@avylove

I have some code that examines modules and am getting test failures with pkgutil.get_loader() returning
AssertionRewritingHook objects instead of a pkgutil.ImpLoader instance.

This is with user-installed pytest 3.1.2 on Fedora 25 (Python 3.5.3)

Here's an example which demonstrates the problem.
Running pytest against it generates the error:
AttributeError: 'AssertionRewritingHook' object has no attribute 'get_filename'

import os
import pkgutil
import unittest

def get_path(modname):

    path = None
    loader = pkgutil.get_loader(modname)
    if loader:
        path = os.path.dirname(loader.get_filename())
    return path

class TestGetPath(unittest.TestCase):
 
    def test_load_entry_point_module(self):
        self.assertEqual(get_path(__name__), os.path.dirname(__file__))

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanism

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions