Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys.modules is called on import #10

Closed
toejough opened this issue Oct 17, 2018 · 0 comments
Closed

sys.modules is called on import #10

toejough opened this issue Oct 17, 2018 · 0 comments

Comments

@toejough
Copy link
Contributor

classic error - the modules dict is defined at import time as a default, so if dado happens to be imported before the targeted test module, that module won't show up and dado will freak out when it's called and tries to update the calling module.

toejough added a commit that referenced this issue Oct 17, 2018
**Problem:**
The main problem was that the tests weren't passing when run, due to
some import semantics, depending on how you called the tests.

Other problems:
* import-time sys.modules use is a bad practice
* functions were getting set in the __dict__ rather than on the module,
which was sometimes leading to problems with dir not showing the
functions.

**Analysis:**
Issues #10 and #6 didn't seem to really be causing problems on inspection.
They were updated/addressed anyway because the updates follow best practices.

Updating the tests was the bigger piece - they now run reliably and
actually directly test what the module is supposed to do, instead of
mucking about with the mock module.

**Resolution:**
Update the tests to be more direct and functional than abstract and
unit-test-y.

Use a robust import mechanism for the testing.

Use the sys.modules dict *in* the function rather than at import time.

Use setattr on the target module rather than accessing its __dict__.

**Testing:**
Ran the tests.

**Documentation:**
None.

**Impact:**
Patch - small fixups, mostly to the tests.
toejough added a commit that referenced this issue Oct 17, 2018
toejough added a commit that referenced this issue Oct 17, 2018
toejough added a commit that referenced this issue Oct 17, 2018
**Problem:**
The main problem was that the tests weren't passing when run, due to
some import semantics, depending on how you called the tests.

Other problems:
* import-time sys.modules use is a bad practice
* functions were getting set in the __dict__ rather than on the module,
which was sometimes leading to problems with dir not showing the
functions.

**Analysis:**
Issues #10 and #6 didn't seem to really be causing problems on inspection.
They were updated/addressed anyway because the updates follow best practices.

Updating the tests was the bigger piece - they now run reliably and
actually directly test what the module is supposed to do, instead of
mucking about with the mock module.

**Resolution:**
Update the tests to be more direct and functional than abstract and
unit-test-y.

Use a robust import mechanism for the testing.

Use the sys.modules dict *in* the function rather than at import time.

Use setattr on the target module rather than accessing its __dict__.

**Testing:**
Ran the tests.

**Documentation:**
None.

**Impact:**
Patch - small fixups, mostly to the tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant