testbook icon indicating copy to clipboard operation
testbook copied to clipboard

Support multiple cells with the same tag

Open fcollonval opened this issue 5 years ago • 8 comments

First of thanks for this really interesting package.

Here is a suggestion: could the code gather all cells with the provided tags to be executed instead of returning the first tagged cell found?

fcollonval avatar Nov 03 '20 13:11 fcollonval

Hey, thanks for raising this issue. I think it definitely makes sense to gather all cells with the same tag. I will take this up.

Edit: Seems like there are a few edge cases where gathering all cells with same tag would not make sense, I will document these and come up with a solution soon and post it here.

rohitsanj avatar Nov 03 '20 17:11 rohitsanj

@rohitsanj Thanks a lot for the reply. I look forward to hear about your solution.

fcollonval avatar Nov 04 '20 08:11 fcollonval

@fcollonval @rohitsanj Any updates on this? A few of user want the ability to separate cells for readability purposes, but group them logically when testing via the same tag

devstein avatar Apr 29 '21 16:04 devstein

@devstein Thanks for the follow up! I apologize for the delay. I will try and implement this over the coming weekend.

rohitsanj avatar Apr 30 '21 03:04 rohitsanj

So, I ran into some design issues while trying to implement this. Maybe you can give me your feedback on this.

Let's say you have a notebook with cells as:

cell 0 ('tag1', 'tag2') cell 1 ('tag3') cell 2 ('tag2') cell 3 ('tag1') cell 4 cell 5 ('tag1')

The issue is as follows: with the current implementation, when we specify testbook('nb.ipynb', execute=['tag3', 'tag1'], it will execute the cells tagged by those tags in the specified order i.e execute cell 1 and then cell 0. If we were to support multiple cells with same tag, we will have to execute the cells linearly, because otherwise the order becomes ambiguous.

For example, if execute=['tag3', 'tag1'] which means tag3 will fetch cells [1] and tag1 will fetch cells [0, 3, 5] Now, there'd be two ways to go about this:

  • Does the user want testbook to execute all cells tagged by 'tag3' and then, execute all cells tagged with 'tag1' ?
  • OR, Does the user want testbook to execute linearly, which would combine to give [0, 1, 3, 5]

It is these ambiguities that I wanted to highlight earlier. I'd like to hear your thoughts on this. @devstein @fcollonval

cc @MSeal

rohitsanj avatar May 08 '21 17:05 rohitsanj

I would say

the user want testbook to execute linearly, which would combine to give [0, 1, 3, 5]

The unordered execution sounds odd as it means the intrinsic way to execute the notebook is unordered; aka when you run manually the notebook. This is a bad practice that will confuse most users.

fcollonval avatar May 09 '21 08:05 fcollonval

@rohitsanj I agree with @fcollonval, keeping it linear is most intuitive.

If executing the notebook in a tag-based order is desirable, then I think it makes sense to have a separate execution flag for enabling that behavior.

devstein avatar May 10 '21 14:05 devstein

@rohitsanj +1 for keeping it linear, as it's consistent with how manual runs work.

Uznick avatar Aug 31 '22 10:08 Uznick