As for Python, you have three modules:
The file that you run from the command line, the main entry point, is always saved as the __main__ module. If you import moduleA anywhere in the code, Python sees this as separate from the __main__ module and creates a new module object instead. Thus, you have two separate MyEnum classes:
__main__.MyEnummoduleA.MyEnum
Their members are different and therefore cannot be equal.
Your test passes if, instead of import moduleA you used import __main__ as moduleA or you used a separate script file to manage the test; this separate file will become __main__ :
#!/usr/bin/python3 # test.py, separate from moduleA.py and moduleB.py import moduleA import moduleB if __name__ == "__main__": myVar = moduleA.MyEnum.B moduleB.doStuff(myVar)
Another workaround would be to tell Python that __main__ and moduleA are the same thing; before importing moduleA (or moduleB , which imports moduleA ), you can add another entry to sys.modules :
if __name__ == '__main__': import sys sys.modules['moduleA'] = sys.modules['__main__'] import moduleB
I would not consider this Pythonic.
source share