4
$\begingroup$

In my workflow, when testing/developing packages, It's an common situation to test internal packages functions that has been already loaded with the package, so they are in the MyPackage`Private context.

Today I know 2 options to test these functions.

1- Use full name like: Mypackage`Private`myFunction[x]

2- Comment Begin["`Private`"] and End[], and run the package again.

Number 1 is very verbose. Number 2 is dangerous (I sometimes forgot to uncomment it).

My question is:

There is another way to do that?

I tested the menu option: Notebook Default Context -> Other... But without success.

$\endgroup$
  • 1
    $\begingroup$ In such situations, I usually just add private context to $ContextPath like this: If[FreeQ[$ContextPath, #], PrependTo[$ContextPath, #]] &@"MyPackagePrivate". But I've just tried changing Notebook Default Context and it worked for me, so what precisely is not working in your case? $\endgroup$ – jkuczm Aug 25 '15 at 22:05
  • 1
    $\begingroup$ You can make an input cell with the CellContext being MyPackage`Private` . Then you can use short names for private functions in that cell. You can automate creation of such cells with a palette or e.g. docked cell in your particular notebook. $\endgroup$ – Leonid Shifrin Aug 26 '15 at 20:17
1
$\begingroup$

You can run Begin["Mypackage`Private`"], then call myFunction[x] and any other private functions, followed by End[] in your test notebook or .mt file instead of commenting it in the package.

This way you don't need to modify your package, you only need to write out the context once and it will work the same way every time you run the code, regardless of notebook context options or the value of $ContextPath.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.