8

To test that your program deletes the correct files, you run it first in a logging-only mode (by commenting-out delete lines or overriding your delete method to be a logging method).

for file_path in file_paths: print('deleting', file_path) # delete(file_path) 

What can this kind of testing be called? I thought it was dry-run, but it looks like dry-run actually means to hand-follow the code with a tracetable.

5
  • 1
    See softwareengineering.stackexchange.com/a/371597 for some information about the terms dry-run and trace table. Commented Aug 28, 2024 at 12:58
  • 6
    As usual when people ask relevant questions about terminology, there are close-votes for "opinion based". Unfortunately, on many terms there are no authoritative definition but the industry has nevertheless a consensus. And sometimes even the question is closed before someone who has found an authoritative answer can post it. Terminology is at the core of every engineering discipline. Commented Aug 28, 2024 at 23:28
  • 1
    @Christophe: The existence of a definition does not somehow exclude any other possible definition from existing or being considered valid. This is why it's opinionated: one source's definition has no bearing on another, it's about what you subscribe to (which could also be both, or neither), making it subjective. In OP's case, they seem to be making that exact mistake in assuming that 'dry run' could only have one possible meaning and that therefore all other meanings are invalid - which is precisely what makes this not meaningfully answerable other than pointing out that's not how words work. Commented Aug 29, 2024 at 1:55
  • 3
    @Flater: come on, I think this is very case-dependent. The existing answers show this is answerable in a meaningful manner, we did not get a dozen different opinions about the term, and I don't think any of the answers give the impression 'dry run' is a term restricted to testing. There are definitely other situations / terms where I agree to all of what you wrote above, but in this case I think it is ok to leave the question open. Commented Aug 29, 2024 at 5:37
  • Exactly! There are 3 kinds of terminological questions: 1) there is an authoritative answer (ISO or IEEE or other broadly accepted body); 2) there is no such definition, but a convergence between practitionners; 3) there is no convergence. I agree that 3 is definitively opinion based, and2 not really but requires the question to remain open to see there's a general agreement. 1 is not an opinion (unless we start to qualify the scientific fact that earth is a globe an opinion): these definitions were included in standards on purpose, to avoid lots of opinion-based discussions later. Commented Aug 29, 2024 at 6:54

5 Answers 5

29

I would call that a dry-run: a dry run is one that has no effect. Lots of programs have dry run modes that print out what they would do, so you can review it before committing to the operation.

it looks like dry-run actually means to hand-follow the code with a tracetable.

I have never seen that definition.

8
  • That's the definition I get from the top google results for "dry run code", actually I can't fin a source for dry run meaning anything else (except from the answers and comments on this page). Commented Aug 28, 2024 at 15:12
  • 1
    I've also heard the term used this way, but OP says they "comment out" lines Commented Aug 28, 2024 at 20:15
  • Excellent! I would have said rehearsal but dry run appears closer: english.stackexchange.com/a/421368/373969 - But I know this practice in a slightly different way, where a parameter (option in comman line, checkbox in a GUI) allows to chose the one or the other at runtime. You can then speak of a "test run" before the real run. Commented Aug 28, 2024 at 23:24
  • @Ewan Whether you comment out the lines or have conditional logic that intentionally skips them in certain scenarios is an implementation detail. In either case, intentionally running the application in a way that skips over these instructions is functionally a dry run. Commented Aug 29, 2024 at 1:56
  • 2
    @minseong Wikipedia: "For example, rsync (...) has a "dry-run" option users can use to check that their command-line arguments are valid and to simulate what would happen when actually copying the data." - while there's no explicit definition in the article, they do give an example of a dry run that consists of simulating what would happen without actually executing the actions. (Powershell has a similar option called "WhatIf" as a general shell convention, so I suppose you could also call it a "what-if" mode). Commented Aug 29, 2024 at 10:23
10

Dry-run as a term is definitely ok. Still I think this kind of testing - with manually commenting in and out certain lines - is not state-of-the-art anymore. The better alternative is to embed the code into a function where can control whether the deletion happens or not, i.e.:

def delete_files(file_paths,log_only=False) for file_path in file_paths: if log_only: print('deleting', file_path) ' or log somewhere else else: delete(file_path) 

One can call this function inside an automated test (with log_only set to True, and some extra code to validate only the correct files will be deleted). Such a test is something I would call a unit test with disabled file system access, or maybe a unit test in dry-run mode.

As mentioned by @chepner in a comment, a more streamlined approach is to provide the delete function as a parameter:

def delete_files(file_paths,delete_func=delete) for file_path in file_paths: delete_func(file_path) 

In unit tests, just call

 delete_files(file_paths,lambda x:print('deleting', x)) 

or, even better, pass a function which collects the file names in a list, so it will be easy to check the content of the list afterwards.

(I did not test this code, hope I got the Python syntax right).

4
  • 1
    Rather than a Boolean flag, make delete itself a parameter that can take a log function instead of an actual file-deletion function. Commented Aug 28, 2024 at 13:37
  • @chepner: I agree with that, as it would allow the dry run to confirm that the delete_funct(file_path, log_files) call itself knows what the file path it will be deleting, and doing additional details like, perhaps, figuring out from what current working directory it would be trying to delete the file from. Commented Aug 28, 2024 at 23:48
  • I don't think the implementation suggestions add anything to "what is this called" and besides that completely miss the nuance of what are you actually doing. If someone told me they were writing unit tests for a one-off script cleaning up some files on their workstation I would be questioning if they don't have enough real work to do. If they told me they were implementing a user facing application which would delete user documents and they weren't planning to include UI showing what would be deleted ahead of time I would be removing their commit privileges from the repository. Commented Aug 30, 2024 at 15:11
  • @user3067860: the "what is this called" has already a good answer, there is no point in repeating that again. And I am sure readers can decide by themselve whether my suggestion to make the code suitable for automated tests fits to their context or not. Commented Aug 30, 2024 at 19:51
2

Since the OP and comments do mention some idea of "What consensus has the community arrived on?" I think its worth mentioning a couple of examples that I come across regularly.

--dry-run is used by kubectl (and followed by helm) to give a report of what actions would be taken, without actually changing anything in the kubernetes cluster.

--check is used by isort and black (formatters in the python ecosystem) to avoid reformatting your code, but still get a report (and error code) if any files are not compliant to the code standards. Useful in CI where the changes would not be persisted anyways.

The Pantsbuild tool also uses --check when running the pants tailor command to autogenerate build metadata. Using --check gives a report of what metadata would be generated, without actually making any changes. Again, useful in CI to cause a failure if something was missed.

In an effort to make this feel more like a good answer instead of just a random list: I do think there is some value in following community standards, roughly defined as they may be, so seeing how some fairly large/well-known projects [no data to cite, just my impression] handle this type of behaviour hopefully allows you to pick terminology in your own project that meets the expectations of your users (in this case, users probably means other developers on your project).

3
  • 1
    A couple more examples from the wild: git merge --no-commit, git push --dry-run, and PowerShell's Remove-Item -WhatIf. There also are some inverse examples - commands that normally ask for confirmation before proceeding, unless provided with a certain argument, like apt-get install -y, Windows's rmdir /q, or again PowerShell's Remove-Item -Confirm:$false. Commented Aug 29, 2024 at 14:23
  • To add to the --dry-run list: rsync. Commented Aug 30, 2024 at 0:14
  • Liquibase has "update-sql", but I'm pretty sure the way I found this out was searching for "does Liquibase have a dry run command". Commented Aug 30, 2024 at 14:59
-1

A term no-one else has mentioned yet is dummy run.

That can mean a run which doesn't process any ‘real’ data (maybe because it's not given any, or is given only dummy (test) data, or is configured not to process it).

It's not really a technical term, but is used widely in general English; for example, Wiktionary defines it as “A trial or practice before the real attempt.”, which seems to apply well here.  So it should be easily understood.

1
  • 1
    I have never heard this phrase, and I see some online dictionaries variously tag it as British or Australian, so this might be regional. This ngram comparison suggests it is much less widely used than the alternatives trial run, dry run, or practice run. Commented Aug 29, 2024 at 22:48
-2

This sounds like Kent Beck's Log String Pattern. BTW, I prefer your suggestion of overriding your delete method to be a logging method. Put it under control of a command line parameter, so you aren't testing a slightly different build of the code.