Skip to content

Conversation

kmvanbrunt
Copy link
Member

@kmvanbrunt kmvanbrunt commented Aug 20, 2020

The following error occured when CommandSet that uses as_subcommand_to decorator was loaded during cmd2.Cmd.__init__().

AttributeError: 'Cmd' object has no attribute 'disabled_commands'

The fix was to move the loading code after all Cmd attributes have been created.

This also added in improved exception message and documentation for testing errors related to poor mocking practices when unit testing.

Closes #981

tleonhardt
tleonhardt previously approved these changes Aug 20, 2020
@codecov
Copy link

codecov bot commented Aug 20, 2020

Codecov Report

Merging #980 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #980   +/-   ##
=======================================
  Coverage   97.82%   97.83%           
=======================================
  Files          22       22           
  Lines        4516     4522    +6     
=======================================
+ Hits         4418     4424    +6     
  Misses         98       98           
Impacted Files Coverage Δ
cmd2/cmd2.py 97.21% <100.00%> (+<0.01%) ⬆️
cmd2/parsing.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5dd2d03...27b1093. Read the comment docs.

tleonhardt
tleonhardt previously approved these changes Aug 20, 2020
@anselor anselor force-pushed the move_module_loading branch 4 times, most recently from 64555b2 to 6b36d64 Compare August 20, 2020 19:12
tleonhardt
tleonhardt previously approved these changes Aug 20, 2020

subcommand_valid, errmsg = self.statement_parser.is_valid_command(subcommand_name, is_subcommand=True)
if not subcommand_valid:
raise CommandSetRegistrationError('Subcommand {} is not valid: {}'.format(str(subcommand_name), errmsg))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding a better error message

@@ -0,0 +1,46 @@
Testing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this section on testing!

@kmvanbrunt kmvanbrunt merged commit 5f76f95 into master Aug 20, 2020
@kmvanbrunt kmvanbrunt deleted the move_module_loading branch August 20, 2020 23:35
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

Successfully merging this pull request may close these issues.

Crash in 1.3.x when a cmd2.Cmd method is mocked
3 participants