Skip to content

Testing code examples import source modules twice #421

@llucax

Description

@llucax

What happened?

We have a new BaseId class that checks that sub-classes don't reuse the same prefix, raising an exception if that happens.

This exception is raised when the module creating the sub-class is being loaded. When testing examples in docstrings using sybil, we are registering the source file as a test file in pytest. But the example being tested is usually also imported by the example itself.

This ends up in the module being imported twice, which usually isn't an issue (although it is wrong), except in cases where loading a module twice fails like in the BaseId case, where 2 classes are being created with the same prefix.

What did you expect instead?

Source files shouldn't be imported twice and just work.

Suggested fix

Probably the more straightforward way to solve this is to stop using sybil to plug into pytest to run pylint on examples, and instead just extract the examples into real files, and let the normal nox check them as we check all other files.

Affected version(s)

No response

Affected part(s)

Tools to configure pytest (part:pytest)

Extra information

Metadata

Metadata

Assignees

No one assigned

    Labels

    part:pytestAffects the configuration of pytesttype:bugSomething isn't working

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions